round c 2b 2b

Solutions on MaxInterview for round c 2b 2b by the best coders in the world

showing results for - "round c 2b 2b"
Elena
23 Oct 2016
1#include<bits/stdc++.h>
2
3int main() {
4	using namespace std;
5	ios_base::sync_with_stdio(false), cin.tie(nullptr);
6
7	int T; cin >> T;
8	for (int case_num = 1; case_num <= T; case_num ++) {
9
10		int64_t L, R; cin >> L >> R; R++;
11		bool parity = 0;
12		int64_t coeff = 1;
13		int64_t ans = 0;
14		while (L < R) {
15			assert(1 <= L && L < R);
16			auto is_good = [&](int64_t v) {
17				assert(v > 0);
18				bool d = v % 2;
19				while (v > 0) {
20					if (v % 2 != d) return false;
21					d = !d;
22					v /= 10;
23				}
24				return d == 0;
25			};
26			while (L < R && L % 10 != 0) {
27				if (is_good(L)) {
28					ans += coeff;
29				}
30				L++;
31			}
32			while (L < R && R % 10 != 0) {
33				--R;
34				if (is_good(R)) {
35					ans += coeff;
36				}
37			}
38
39			if (L == R) break;
40			assert(L % 10 == 0 && R % 10 == 0);
41			assert(L >= 10);
42
43			L /= 10;
44sorry for the error