Submission #121290

#TimeUsernameProblemLanguageResultExecution timeMemory
121290imyujinCoin Collecting (JOI19_ho_t4)C++14
100 / 100
60 ms4984 KiB
#include<stdio.h> #include<algorithm> using namespace std; #define MAXN 100005 using namespace std; typedef long long lint; lint X[2*MAXN], Y[2*MAXN]; int S[2*MAXN][3]; int main(){ int N; lint ans=0; scanf("%d", &N); for(int i=0; i<2*N; i++) scanf("%lld%lld", X+i, Y+i); for(int i=0; i<2*N; i++){ int x, y; if(X[i]<=0) x=1; else if(X[i]>N) x=N; else x=X[i]; y=Y[i]>=2?2:1; ans+=abs(X[i]-x)+abs(Y[i]-y); S[x][y]++; //printf("(%d, %d)\n", x, y); } for(int i=1; i<=N; i++){ S[i][1]--; S[i][2]--; //printf("[%d %d]\n", S[i][1], S[i][2]); } for(int i=1; i<=N; i++){ if((long long)S[i][1]*S[i][2]<0){ if(abs(S[i][1])>abs(S[i][2])){ ans+=abs(S[i][2]); S[i][1]+=S[i][2]; S[i][2]=0; } else{ ans+=abs(S[i][1]); S[i][2]+=S[i][1]; S[i][1]=0; } } ans+=abs(S[i][1]); ans+=abs(S[i][2]); S[i+1][1]+=S[i][1]; S[i+1][2]+=S[i][2]; } printf("%lld", ans); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:20:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<2*N; i++) scanf("%lld%lld", X+i, Y+i);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...