제출 #1310160

#제출 시각아이디문제언어결과실행 시간메모리
1310160tntCoin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define f first #define s second #define int long long //#define sz(v) int(v.size()) #define all(v) v.begin(),v.end() int mod = 1e9 + 7; const int N = 2e5 + 100,k = 317 + 1; const ll inf = 1e18 + 100; int mp[N]; void solve(){ int n; cin >> n; int x[2 * n + 1],y[2 * n + 1]; ll ans = 0,cnt = 0; for(int i = 1; i <= 2 * n; i++){ cin >> x[i] >> y[i]; swap(x[i],y[i]); if(x[i] >= 2){ ans += x[i] - 2; x[i] = 2; } else{ ans += 1 - x[i]; x[i] = 1; } } for(int i = 1; i <= 2 * n; i++){ if(y[i] < 1){ ans += 1 - y[i]; y[i] = 1; } else if(y[i] > n){ ans += y[i] - n; y[i] = n; } if(x[i] == 1) cnt++; mp[y[i]]++; } for(int i = 1; i <= n; i++) mp[i] += mp[i - 1]; ans += (n - min(cnt,2 * n - cnt)); cnt = 0; for(int i = 1; i <= n; i++){ ans += abs(2 * i - mp[i]); } cout << ans; } signed main(){ //freopen("time.in", "r", stdin); //freopen("time.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int t1 = 1; while(t1--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...