Submission #236714

# Submission time Handle Problem Language Result Execution time Memory
236714 2020-06-03T06:34:23 Z meatrow Remittance (JOI19_remittance) C++17
0 / 100
5 ms 384 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;

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();
	for (int i = pos; i < pos + n && pos + n <= lul.size(); 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];
	}
	if (pos == lul.size()) {
		kek = 0;
	}
	ll heh = 0;
	for (int i = n - 2, j = 1; i >= max(n - 32, 0); i--, j++) {
		heh += a[i] / (1LL << j);
	}
	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 '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:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = pos; i < pos + n && pos + n <= lul.size(); i++) {
                                   ~~~~~~~~^~~~~~~~~~~~~
remittance.cpp:44:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = pos + n; i < lul.size(); i++) {
                        ~~^~~~~~~~~~~~
remittance.cpp:47:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (pos == lul.size()) {
      ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 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 4 ms 384 KB Output is correct
3 Correct 4 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 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -