Submission #776057

# Submission time Handle Problem Language Result Execution time Memory
776057 2023-07-07T09:04:11 Z mdub Remittance (JOI19_remittance) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
LL power(int n) {  
  if (n == 0) return 1;
  else return 2*(power(n-1));
}

int main () {
  LL n; cin >>n;
  vector<LL> a(n);
  vector<LL> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  LL need = 0;
  bool ok = true;
  for (int i= 0; i < n - 1; i++) {
    if ((a[i] > b[i])) {
	
	if ((a[i] - b[i]) % 2) {
	  a[i + 1] += (a[i] - b[i] + 1) / 2;
	  if (i + 1 > 50) {
	    ok = false;
	  }
	  need += power(i + 1);
	}
	else {
	  a[i + 1] += (a[i] - b[i]) / 2;
	}
      }
      else if (a[i] < b[i]) {
	if (i + 1 > 50) {
	  ok = false;
	}
	LL p = power(i + 1);
	if (to_string(p).size() + to_string((b[i] - a[i])).size() >= 17) {
	  ok = false;
	}
	need += p*(b[i] - a[i]);
	if (need > LL(1e16)) {
	  ok = false;
	}
      }
    
  }
  if (a[n-1] - b[n-1] != need) {
    ok = false;
  }
  if (ok) {
    cout << "YES\n";
  }
  else cout << "NO\n";
    
      
      
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -