Submission #1310163

#TimeUsernameProblemLanguageResultExecution timeMemory
1310163arafatisticCoin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") // #pragma GCC optimization("unroll-loops") // #pragma ("reroll") #define all(v) v.begin(), v.end() #define skip continue; #define gold ios_base::sync_with_stdio(false);cin.tie(NULL); #define xa "\n" #define int long long #define pb push_back #define S second #define F first using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 7; const int MAX = 1e9; const int inf = 1e18; int gcd(int a, int b) { if (b == 0) return a; else if(a == 0) return b; else return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } int cnt[N]; int pref[N]; void solve() { int n; cin >> n; int x[2 * n + 1], y[2 * n + 1]; int ans = 0; int y1 = 0; for(int i = 1; i <= 2 * n; i++){ cin >> x[i] >> y[i]; if(y[i] <= 1){ ans += abs(1 - y[i]); y[i] = 1; } else { ans += abs(y[i] - 2); y[i] = 2; } if(x[i] <= 1){ ans += abs(1 - x[i]); x[i] = 1; } else if(x[i] >= n){ ans += abs(x[i] - n); x[i] = n; } y1 += (y[i] == 1); cnt[x[i]]++; } for(int i = 1; i <= n; i++){ pref[i] = pref[i - 1] + cnt[i]; } ans += abs(n - y1); for(int i = 1; i < n; i++){ ans += abs(2 * i - pref[i]); } cout << ans; } signed main() { gold; //freopen("knight.in", "r", stdin); //freopen("knight.out", "w", stdout); int t = 1; int tt = 0; //cin >> t; while (t--) { tt++; //cout << "Case " << tt << ":" << xa; solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...