Submission #236754

# Submission time Handle Problem Language Result Execution time Memory
236754 2020-06-03T08:22:23 Z meatrow Remittance (JOI19_remittance) C++17
100 / 100
446 ms 52192 KB
#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

ll div(vector<ll>& num, int n) {
	ll res = 0;
	for (int i = 35; i >= 0; i--) {
		vector<ll> den(num.size());
		fill(den.begin() + i, den.begin() + n + i, 1);
		bool ok = true;
		for (int j = num.size() - 1; j >= 0; j--) {
			if (num[j] > den[j]) {
				break;
			}
			if (num[j] < den[j]) {
				ok = false;
			}
		}
		if (!ok) continue;
		res += 1LL << i;
		for (int j = 0; j + 1 < num.size(); j++) {
			num[j] -= den[j];
			if (num[j] < 0) {
				num[j] += 2;
				num[j + 1]--;
			}
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	vector<ll> lul(n + 123);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		lul[i] = a[i] - b[i];
	}
	// t[n - 1] = sigma(2^i * (a[i] - b[i])) / (2^n - 1)
	for (int i = 0; i + 1 < lul.size(); i++) {
		lul[i + 1] += lul[i] / 2;
		lul[i] %= 2;
		if (lul[i] < 0) {
			lul[i] += 2;
			lul[i + 1]--;
		}
	}
	if (find(lul.begin(), lul.end(), -1) != lul.end()) {
		cout << "No\n";
		return 0;
	}
	ll kek = div(lul, n);
	if (find(lul.begin(), lul.end(), 1) != lul.end()) {
		cout << "No\n";
		return 0;
	}
	ll heh = 0;
	for (int i = 0; i < n; i++) {
		heh += a[i];
		heh /= 2;
	}
	if (n < 35) {
		ll pw = 1LL << n; 
		ll huh = heh / pw;
		while (huh) {
			heh += huh;
			huh /= pw;
		}
	}
	if (heh < kek) {
		cout << "No\n";
		return 0;
	}
	a[n - 1] -= 2 * kek;
	a[0] += kek;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] < b[i] || (a[i] - b[i]) % 2) {
			cout << "No\n";
			return 0;
		}
		ll mem = (a[i] - b[i]) / 2;
		a[i] -= mem * 2;
		a[i + 1] += mem; 
	}
	if (a[n - 1] != b[n - 1]) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
	return 0;
}

Compilation message

remittance.cpp: In function 'll div(std::vector<long long int>&, int)':
remittance.cpp:26:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j + 1 < num.size(); j++) {
                   ~~~~~~^~~~~~~~~~~~
remittance.cpp: In function 'int main()':
remittance.cpp:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i + 1 < lul.size(); i++) {
                  ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 288 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 4 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 432 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 4 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 288 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 4 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 432 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 4 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 286 ms 43128 KB Output is correct
64 Correct 258 ms 35576 KB Output is correct
65 Correct 392 ms 50552 KB Output is correct
66 Correct 238 ms 35696 KB Output is correct
67 Correct 274 ms 37112 KB Output is correct
68 Correct 269 ms 39288 KB Output is correct
69 Correct 427 ms 51192 KB Output is correct
70 Correct 258 ms 35696 KB Output is correct
71 Correct 263 ms 36984 KB Output is correct
72 Correct 253 ms 39288 KB Output is correct
73 Correct 383 ms 51064 KB Output is correct
74 Correct 226 ms 35580 KB Output is correct
75 Correct 247 ms 36984 KB Output is correct
76 Correct 298 ms 39288 KB Output is correct
77 Correct 394 ms 51168 KB Output is correct
78 Correct 318 ms 43256 KB Output is correct
79 Correct 313 ms 43384 KB Output is correct
80 Correct 333 ms 43360 KB Output is correct
81 Correct 334 ms 43256 KB Output is correct
82 Correct 234 ms 35576 KB Output is correct
83 Correct 135 ms 27768 KB Output is correct
84 Correct 221 ms 35576 KB Output is correct
85 Correct 446 ms 52192 KB Output is correct
86 Correct 414 ms 52088 KB Output is correct
87 Correct 320 ms 44512 KB Output is correct
88 Correct 355 ms 44408 KB Output is correct