Submission #496133

#TimeUsernameProblemLanguageResultExecution timeMemory
496133Jarif_RahmanCoin Collecting (JOI19_ho_t4)C++17
100 / 100
60 ms5692 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<int>> v(2, vector<int>(n, 0)); ll ans = 0; for(int i = 0; i < 2*n; i++){ ll x, y; cin >> x >> y; if(x > n) ans+=x-n, x = n; if(x < 1) ans+=-x+1, x = 1; if(y > 2) ans+=y-2, y = 2; if(y < 1) ans+=-y+1, y = 1; x--, y--; v[y][x]++; } int a = 0, b = 0; for(int i = 0; i < n; i++){ a+=v[0][i]-1, b+=v[1][i]-1; if(a > 0 && b < 0){ int mn = min(a, -b); a-=mn, b+=mn, ans+=mn; } else if(b > 0 && a < 0){ int mn = min(-a, b); a+=mn, b-=mn, ans+=mn; } ans+=abs(a)+abs(b); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...