Submission #749085

#TimeUsernameProblemLanguageResultExecution timeMemory
7490851075508020060209tcCoin Collecting (JOI19_ho_t4)C++14
100 / 100
179 ms7484 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int n; int freq[4][500005]; int ps[3][500005]; int ans; signed main(){ cin>>n; ans=0; for(int i=1;i<=n*2;i++){ int a;int b; cin>>a>>b; if(b<=1){ ans+=abs(b-1); b=1; }else{ ans+=abs(b-2); b=2; } if(a<=1){ ans+=abs(1-a); a=1; } if(a>=n){ ans+=abs(n-a); a=n; } freq[b][a]++; } for(int i=1;i<=n;i++){ ps[1][i]=ps[1][i-1]+freq[1][i]; ps[2][i]=ps[2][i-1]+freq[2][i]; ps[3][i]=ps[1][i]+ps[2][i]; } int d1=0; int d2=0; for(int i=1;i<=n;i++){ d1+=freq[1][i]-1; d2+=freq[2][i]-1; if(d1>0&&d2<0){ int t=min(d1,-d2); ans+=t; d1-=t;d2+=t; } if(d1<0&&d2>0){ int t=min(-d1,d2); ans+=t; d1+=t;d2-=t; } ans+=abs(ps[3][i]-i*2); } cout<<ans<<endl; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:36:9: warning: array subscript 3 is above array bounds of 'long long int [3][500005]' [-Warray-bounds]
   36 |     ps[3][i]=ps[1][i]+ps[2][i];
      |     ~~~~^
joi2019_ho_t4.cpp:7:5: note: while referencing 'ps'
    7 | int ps[3][500005];
      |     ^~
joi2019_ho_t4.cpp:55:18: warning: array subscript 3 is above array bounds of 'long long int [3][500005]' [-Warray-bounds]
   55 |     ans+=abs(ps[3][i]-i*2);
      |              ~~~~^
joi2019_ho_t4.cpp:7:5: note: while referencing 'ps'
    7 | int ps[3][500005];
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...