Submission #257490

#TimeUsernameProblemLanguageResultExecution timeMemory
257490Osama_AlkhodairyCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n; vector <vector <int> > a; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(2, vector <int>(n, 0)); ll ans = 0; for(int i = 0 ; i < 2 * n ; i++){ int x, y; cin >> x >> y; int nx = min(n, max(1, x)); int ny = min(2, max(1, y)); ans += abs(nx - x) + abs(ny - y); a[ny - 1][nx - 1]++; } vector <vector <int> > sum(2, vector <int>(n, 0)); for(int i = 0 ; i < 2 ; i++){ for(int j = n - 1 ; j >= 0 ; j--){ if(j < n - 1) sum[i][j] = sum[i][j + 1]; sum[i][j] += a[i][j]; } } for(int itt = 0 ; itt < 2 ; itt++){ int cur = a[0][0] + a[1][0]; for(int j = 1 ; j < n ; j++){ int g = max(cur - 2 * j, 0); cur += a[0][j] + a[1][j]; int s0 = sum[0][j], s1 = sum[1][j]; while(g--){ int f = 0; if(s0 < s1){ if(a[0][j - 1] > 1) f = 0; else f = 1; } else{ if(a[1][j - 1] > 1) f = 1; else f = 0; } a[f][j - 1]--; a[f][j]++; ans++; } } for(int i = 0 ; i < 2 ; i++){ reverse(a[i].begin(), a[i].end()); } } for(int j = 0 ; j < n ; j++){ if(a[0][j] != 1) ans++; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...