Submission #97526

#TimeUsernameProblemLanguageResultExecution timeMemory
97526dalgerokCoin Collecting (JOI19_ho_t4)C++17
0 / 100
3 ms512 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin >> n; int a[3][n + 1]; memset(a, 0, sizeof(a)); long long ans = 0; for(int i = 1; i <= 2 * n; i++){ int x, y; cin >> x >> y; if(y < 1){ ans += 1 - y; y = 1; } else if(y > 2){ ans += y - 2; y = 2; } if(x < 1){ ans += 1 - x; x = 1; } else if(x > n){ ans += x - n; x = n; } a[y][x] += 1; } vector < int > q[3], s[3]; for(int i = 1; i <= n; i++){ q[1].push_back(i); q[2].push_back(i); for(int j = 1; j <= 2; j++){ for(int k = 1; k <= a[j][i]; k++){ s[j].push_back(i); } } for(int j = 1; j <= 2; j++){ while(!q[j].empty() && !s[j].empty()){ ans += abs(q[j].back() - s[j].back()); q[j].pop_back(); s[j].pop_back(); } } for(int j = 1; j <= 2; j++){ while(!q[j].empty() && !s[3 - j].empty()){ ans += abs(q[j].back() - s[3 - j].back()) + 1; q[j].pop_back(); s[j].pop_back(); } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...