제출 #1208167

#제출 시각아이디문제언어결과실행 시간메모리
1208167sangerafCoin Collecting (JOI19_ho_t4)C++20
100 / 100
26 ms2008 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; int ans = 0; vector<array<int, 2>> db(n+1, {0, 0}); for(int i=0; i<2*n; i++){ int x, y; cin >> x >> y; if(x < 1){ ans += 1 - x; x = 1; }else if(x > n){ ans += x - n; x = n; } if(y < 1){ ans += 1 - y; y = 1; }else if(y > 2){ ans += y - 2; y = 2; } db[x][y-1]++; } for(int i=1; i<=n; i++){ ans += abs(db[i-1][0]); ans += abs(db[i-1][1]); db[i][0] += db[i-1][0]; db[i][1] += db[i-1][1]; db[i][0]--; db[i][1]--; while(db[i][0] < 0 && db[i][1] > 0){ db[i][0]++; db[i][1]--; ans++; } while(db[i][0] > 0 && db[i][1] < 0){ db[i][0]--; db[i][1]++; ans++; } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...