Submission #121286

#TimeUsernameProblemLanguageResultExecution timeMemory
121286youngyojunCoin Collecting (JOI19_ho_t4)C++11
100 / 100
69 ms1272 KiB
#include <bits/stdc++.h> #define upmin(a,b) (a)=min((a),(b)) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = 100055; int A[MAXN][2]; ll Ans; int N; int main() { ios::sync_with_stdio(false); cin >> N; for(int i = N<<1, x, y; i--;) { cin >> x >> y; if(x < 1) { Ans += 1-x; x = 1; } if(N < x) { Ans += x-N; x = N; } if(2 < y) { Ans += y-2; y = 2; } if(y < 1) { Ans += 1-y; y = 1; } A[x][y-1]++; } for(int i = 1; i <= N; i++) { A[i][0]--; A[i][1]--; } for(int i = 1; i < N; i++) { if(0 <= A[i][0] && 0 <= A[i][1]) { Ans += A[i][0] + A[i][1]; } else if(A[i][0] <= 0 && A[i][1] <= 0) { Ans -= A[i][0] + A[i][1]; } else if(abs(A[i][0]) < abs(A[i][1])) { Ans += abs(A[i][0]); A[i][1] += A[i][0]; A[i][0] = 0; Ans += abs(A[i][1]); } else { Ans += abs(A[i][1]); A[i][0] += A[i][1]; A[i][1] = 0; Ans += abs(A[i][0]); } A[i+1][0] += A[i][0]; A[i+1][1] += A[i][1]; } Ans += abs(A[N][0]); cout << Ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...