답안 #236708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236708 2020-06-03T06:10:47 Z meatrow 송금 (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);
	bool nonzero = false;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		lul[i] = a[i] - b[i];
		nonzero |= lul[i];
	}
	if (!nonzero) {
		cout << "Yes\n";
		return 0;
	}
	// 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; 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];
	}
	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; 
	}
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Compilation message

remittance.cpp: In function 'int main()':
remittance.cpp:29:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i + 1 < lul.size(); i++) {
                  ~~~~~~^~~~~~~~~~~~
remittance.cpp:50:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = pos + n; i < lul.size(); i++) {
                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -