Submission #300926

#TimeUsernameProblemLanguageResultExecution timeMemory
300926pit4hCoin Collecting (JOI19_ho_t4)C++14
37 / 100
85 ms10488 KiB
#include<bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #ifndef LOCAL #define cerr if(0)cerr #endif using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; vector<vector<int>> cnt(n+1, vector<int>(3)); ll ans = 0; for(int i=0; i<2*n; ++i) { int x, y; cin>>x>>y; int nx = max(1, min(n, x)); int ny = max(1, min(2, y)); cnt[nx][ny]++; ans += abs(x - nx) + abs(y - ny); } vector<int> filled(3); for(int i=1; i<=n; ++i) { for(int j=1; j<=2; ++j) { int fill = min(i - filled[j], cnt[i][j]); ans += (ll)(i-filled[j]-1) * fill - fill * (fill-1) / 2; filled[j] += fill; cnt[i][j] -= fill; } for(int j=1; j<=2; ++j) { int fill = min(i - filled[j%2+1], cnt[i][j]); ans += (ll)(i-filled[j%2+1]-1) * fill - fill * (fill-1) / 2 + fill; filled[j%2+1] += fill; cnt[i][j] -= fill; } if(i+1 <= n) { for(int j=1; j<=2; ++j) { ans += cnt[i][j]; cnt[i+1][j] += cnt[i][j]; } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...