Submission #901413

#TimeUsernameProblemLanguageResultExecution timeMemory
901413sunwukong123Coin Collecting (JOI19_ho_t4)C++14
100 / 100
43 ms5988 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) #else #define debug(...) #endif const int MAXN = 100005; const int inf=1000000500ll; const long long oo =1000000000000000500ll; const int MOD = (int)1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int,int> pi; int A[MAXN][3]; int ans; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i=1;i<=2*n;i++){ int x,y;cin>>x>>y; int nx,ny; if(y>=2)ny=2; else ny=1; if(x<=1)nx=1; else if(x<=n)nx=x; else nx=n; ans+=abs(x-nx) + abs(y-ny); A[nx][ny]++; } int L=0,R=0; for(int i=1;i<=n;i++){ L+=A[i][1]-1; R+=A[i][2]-1; while(L<0&&R>0){ ++L;--R;++ans; } while(L>0&&R<0){ --L;++R;++ans; } ans+=abs(L)+abs(R); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...