제출 #1222084

#제출 시각아이디문제언어결과실행 시간메모리
1222084thangdz2k7Coin Collecting (JOI19_ho_t4)C++20
100 / 100
37 ms1236 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int n, cnt[2][MAX]; long long ans = 0; void process(){ cin >> n; for (int i = 0; i < n * 2; ++ i){ int x, y; cin >> x >> y; x --, y --; if (y <= 0){ ans += -y; y = 0; } else { ans += y - 1; y = 1; } if (x < 0){ ans += -x; x = 0; } if (x >= n){ ans += x - n + 1; x = n - 1; } cnt[y][x] ++; } int a = 0, b = 0; for (int i = 0; i < n; ++ i){ a += cnt[0][i] - 1; b += cnt[1][i] - 1; while (a < 0 && b > 0) { ans ++; a ++, b --; } while (a > 0 && b < 0){ ans ++; a --, b ++; } ans += abs(a) + abs(b); } cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); process(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...