Submission #871119

#TimeUsernameProblemLanguageResultExecution timeMemory
871119ToighetLPHMCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> //#define int long long #define FOR(i,a,b) for (int i=(a);i<=(b);i++) #define FOD(i,a,b) for (int i=(a);i>=(b);i--) #define bit(x,y) ((x)>>(y))&1 #define pb push_back #define ll long long #define ii pair < int,int > #define f first #define s second #define M 1000000007 #define N 100005 using namespace std; int cnt[N][2]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); //freopen(".inp","r",stdin); //freopen(".out","w",stdout); int n,res=0; cin>>n; FOR(i,1,2*n) { int x,y; cin>>x>>y; if (x<1) { res+=1-x; x=1; } else if (x>n) { res+=x-n; x=n; } if (y>2) { res+=y-2; y=2; } else if (y<1) { res+=1-y; y=1; } ++cnt[x][y]; } int x=0,y=0; FOR(i,1,n) { --cnt[i][1]; --cnt[i][2]; x+=cnt[i][1]; y+=cnt[i][2]; if (x<0 && y>0) { int z=min(abs(x),abs(y)); x+=z; y-=z; res+=z; } else if (x>0 && y<0) { int z=min(abs(x),abs(y)); x-=z; y+=z; res+=z; } res+=abs(x)+abs(y); } cout<<res; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   47 |         --cnt[i][2];
      |           ~~~~~~~~^
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...