제출 #1149669

#제출 시각아이디문제언어결과실행 시간메모리
1149669gazizmadi11Coin Collecting (JOI19_ho_t4)C++20
100 / 100
24 ms2796 KiB
//gm --- akezhon #include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define pf push_front #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NE r < tl || tr < l #define double long double #define int long long using namespace std; const int N=3e5+7; const int mod=1e9+7; const int inf=2e18; int a[N][3]; void AlemAmenov(){ int ans=0; int n; cin >> n; for(int x, y, i=1; i <= n*2; i++){ cin >> x >> y; if(y<=1){ ans+=1-y; if(x < 1){ ans += 1-x; a[1][1]++; } else if(n < x){ ans += x-n; a[n][1]++; } else{ a[x][1]++; } } else{ ans+=y-2; if(x < 1){ ans += 1-x; a[1][2]++; } else if(n < x){ ans += x-n; a[n][2]++; } else{ a[x][2]++; } } } int dolg1=0, dolg2=0; for(int i=1; i <= n; i++){ dolg1 += a[i][1]-1; dolg2 += a[i][2]-1; if(dolg1 < 0 && 0 < dolg2){ int mn = min(abs(dolg1), abs(dolg2)); ans += mn; dolg1 += mn; dolg2 -= mn; } if(dolg2 < 0 && 0 < dolg1){ int mn = min(abs(dolg1), abs(dolg2)); ans += mn; dolg2 += mn; dolg1 -= mn; } ans += abs(dolg1); ans += abs(dolg2); } cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int RealName=1; // cin >> RealNam; // srand(time(0)); while(RealName--) AlemAmenov(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...