#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;
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 + 33);
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;
}
reverse(lul.begin(), lul.end());
int pos = find(lul.begin(), lul.end(), 1) - lul.begin();
if (pos == lul.size()) {
cout << "Yes\n";
return 0;
}
for (int i = pos; i < pos + n; i++) {
if (!lul[i]) {
cout << "No\n";
return 0;
}
}
ll kek = 1;
for (int i = pos + n; i < lul.size(); i++) {
kek = kek * 2 + lul[i];
}
ll mem = kek;
for (int i = n - 2; i >= 0; i--) {
ll prev = kek;
kek = kek * 2 + (a[i] - b[i]);
if (kek < 0 || kek > 1e15) {
cout << "No\n";
return 0;
}
}
if (a[0] + mem < 2 * kek) {
cout << "No\n";
} else {
cout << "Yes\n";
}
return 0;
}
Compilation message
remittance.cpp: In function 'int main()':
remittance.cpp:23:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i + 1 < lul.size(); i++) {
~~~~~~^~~~~~~~~~~~
remittance.cpp:37:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pos == lul.size()) {
~~~~^~~~~~~~~~~~~
remittance.cpp:48:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = pos + n; i < lul.size(); i++) {
~~^~~~~~~~~~~~
remittance.cpp:53:6: warning: unused variable 'prev' [-Wunused-variable]
ll prev = kek;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |