Submission #776009

#TimeUsernameProblemLanguageResultExecution timeMemory
776009gun_ganCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 7; ll N; ll a[MX][3], b[MX]; ll ans = 0; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N; for(int i = 0; i < 2 * N; i++) { ll x, y; cin >> x >> y; if(1 <= x && x <= N && 1 <= y && y <= 2) { a[x][y]++; } else if(1 <= x && x <= N) { if(y > 2) { a[x][2]++; ans += y - 2; } else { a[x][1]++; ans += 1 - y; } } else if(1 <= y && y <= 2) { if(x < 1) { a[1][y]++; ans += 1 - x; } else { a[N][y]++; ans += x - N; } } else { if(y > 2 && x < 1) { a[1][2]++; ans += 1 - x + y - 2; } else if(y > 2 && x > N) { a[N][2]++; ans += x - N + y - 2; } else if(y < 1 && x < 1) { a[1][1]++; ans += 1 - x + 1 - y; } else { a[N][1]++; ans += x - N + 1 - y; } } } ll diff = 0, sum = 0; for(int i = 1; i <= N; i++) { diff += a[i][1]; if(i < N) { sum += a[i][1] + a[i][2]; ans += abs(sum - i * 2); } } ans += abs(diff - N); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...