Submission #321628

#TimeUsernameProblemLanguageResultExecution timeMemory
321628LawlietRemittance (JOI19_remittance)C++17
15 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int lli; const int MAXN = 1000010; const lli INF = 5000000000000000000LL; int n; lli x[MAXN]; lli diff[MAXN]; lli A[MAXN], B[MAXN]; void impossible() { printf("No\n"); exit(0); } void addCross(int i, lli qtd) { if( i >= 62 ) impossible(); lli p = (1LL << (i - 1)); if( qtd > INF/p ) impossible(); x[i] += qtd; x[n] += qtd*p; if( x[n] >= INF ) impossible(); for(int j = i - 1 ; j >= 1 ; j--) x[j] += (1LL << (i - j - 1))*qtd; } int main() { scanf("%d",&n); for(int i = 1 ; i <= n ; i++) { scanf("%lld %lld",&A[i],&B[i]); diff[i] = A[i] - B[i]; } for(int i = 1 ; i < n ; i++) { x[i] = diff[i] + x[i - 1]; if( x[i] < 0 ) addCross( i , -x[i] ); if( x[i]%2 == 1 ) addCross( i , 1 ); x[i] = x[i]/2; } lli s = diff[n] + x[n - 1]; if( s%2 != 0 || s/2 != x[n] ) impossible(); for(int k = 1 ; k <= 100 ; k++) { for(int i = 1 ; i <= n ; i++) { lli send = min( x[i] , A[i]/2 ); x[i] -= send; A[i] -= 2*send; A[(i == n) ? 1 : i + 1] += send; } } for(int i = 1 ; i <= n ; i++) if( A[i] != B[i] ) impossible(); printf("Yes\n"); }

Compilation message (stderr)

remittance.cpp: In function 'int main()':
remittance.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
remittance.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%lld %lld",&A[i],&B[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...