Submission #1309725

#TimeUsernameProblemLanguageResultExecution timeMemory
1309725StefanSebezCoin Collecting (JOI19_ho_t4)C++20
100 / 100
42 ms1196 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ld long double #define mp make_pair const int N=1e5+50; int a[N][2]; int main(){ int n;scanf("%i",&n); ll res=0; for(int i=1;i<=2*n;i++){ int x,y;scanf("%i%i",&x,&y); if(y<1)res+=1-y,y=1; if(y>2)res+=y-2,y=2; if(x<1)res+=1-x,x=1; if(x>n)res+=x-n,x=n; a[x][y-1]++; } for(int i=1;i<=n;i++){ a[i][0]--; a[i][1]--; int x=min(abs(a[i][0]),abs(a[i][1])); if(a[i][0]<0&&a[i][1]>0){ a[i][0]+=x,a[i][1]-=x; res+=x; } if(a[i][0]>0&&a[i][1]<0){ a[i][0]-=x,a[i][1]+=x; res+=x; } a[i+1][0]+=a[i][0]; a[i+1][1]+=a[i][1]; res+=abs(a[i][0])+abs(a[i][1]); } printf("%lld\n",res); return 0; }

Compilation message (stderr)

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