Submission #340090

#TimeUsernameProblemLanguageResultExecution timeMemory
340090couplefireCoin Collecting (JOI19_ho_t4)C++17
100 / 100
62 ms5100 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 int n; long long ans; int arr[MAXN][2]; int main(){ // freopen("a.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0; i<2*n; i++){ long long a, b; cin >> a >> b; --a; --b; if(a < 0) ans += -a, a = 0; if(a >= n) ans += a-n+1, a = n-1; if(b > 1) ans += b-1, b = 1; if(b < 0) ans += -b, b = 0; arr[a][b]++; } int cur[2] = {0, 0}; for(int i = 0; i<n; i++){ cur[0] += arr[i][0]-1; cur[1] += arr[i][1]-1; for(int j = 0; j<2; j++){ if(cur[j] > 0 && cur[1-j] < 0){ int x = min(cur[j], -cur[1-j]); cur[j] -= x, cur[1-j] += x, ans += x; } } ans += abs(cur[0])+abs(cur[1]); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...