Submission #153822

#TimeUsernameProblemLanguageResultExecution timeMemory
153822arnold518Coin Collecting (JOI19_ho_t4)C++14
100 / 100
71 ms5816 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N; int A[3][MAXN+10]; ll ans; int main() { int i, j; scanf("%d", &N); for(i=1; i<=2*N; i++) { int x, y; scanf("%d%d", &x, &y); if(x<1) ans+=1-x, x=1; if(x>N) ans+=x-N, x=N; if(y<1) ans+=1-y, y=1; if(y>2) ans+=y-2, y=2; A[y][x]++; } for(i=1; i<N; i++) { if(A[1][i]<1 && A[2][i]>=1) { if(A[1][i]+A[2][i]>=2) { ans+=1-A[1][i]; A[2][i]-=1-A[1][i]; A[1][i]=1; } else { ans+=A[2][i]-1; A[1][i]+=A[2][i]-1; A[2][i]=1; } } if(A[2][i]<1 && A[1][i]>=1) { if(A[1][i]+A[2][i]>=2) { ans+=1-A[2][i]; A[1][i]-=1-A[2][i]; A[2][i]=1; } else { ans+=A[1][i]-1; A[2][i]+=A[1][i]-1; A[1][i]=1; } } if(A[1][i]>=1) { ans+=A[1][i]-1; A[1][i+1]+=A[1][i]-1; A[1][i]=1; } else { ans+=1-A[1][i]; A[1][i+1]+=A[1][i]-1; A[1][i]=1; } if(A[2][i]>=1) { ans+=A[2][i]-1; A[2][i+1]+=A[2][i]-1; A[2][i]=1; } else { ans+=1-A[2][i]; A[2][i+1]+=A[2][i]-1; A[2][i]=1; } } ans+=abs(A[1][N]-1); printf("%lld", ans); }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:16:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
joi2019_ho_t4.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...