Submission #236754

#TimeUsernameProblemLanguageResultExecution timeMemory
236754meatrowRemittance (JOI19_remittance)C++17
100 / 100
446 ms52192 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...