Submission #167374

#TimeUsernameProblemLanguageResultExecution timeMemory
167374theStaticMindCoin Collecting (JOI19_ho_t4)C++14
100 / 100
104 ms7400 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n,ans=0; cin>>n; vector<vector<int>> rect(3,vector<int>(n+1,-1)); for(int i=0;i<2*n;i++){ int x,y; cin>>y>>x; int X=x,Y=y; if(x>2){ ans+=x-2; X=2; } if(x<1){ ans+=1-x; X=1; } if(y>n){ ans+=y-n; Y=n; } if(y<1){ ans+=1-y; Y=1; } rect[X][Y]++; } int cnt=0; rect[1][0]=0; rect[2][0]=0; for(int i=1;i<=n;i++){ rect[1][i]+=rect[1][i-1]; rect[2][i]+=rect[2][i-1]; cnt+=abs(rect[1][i-1])+abs(rect[2][i-1]); int& x=rect[1][i]; int& y=rect[2][i]; if(x>0&&y<0){ if(x>-y){ x+=y; cnt-=y; y=0; } else{ y+=x; cnt+=x; x=0; } } else if(x<0&&y>0){ if(-x>y){ x+=y; cnt+=y; y=0; } else{ y+=x; cnt-=x; x=0; } } } cout<<ans+cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...