Submission #527074

#TimeUsernameProblemLanguageResultExecution timeMemory
527074AdamGSCoin Collecting (JOI19_ho_t4)C++17
100 / 100
51 ms6460 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back const int LIM=1e5+7; const ll INF=1e18+7; ll ile[LIM][2]; vector<pair<ll,ll>>V; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; ll ans=0; rep(i, 2*n) { ll a, b; cin >> a >> b; ans+=max(1-a, 0ll); a=max(a, 1ll); ans+=max(a-n, 0ll); a=min(a, n); ans+=max(1-b, 0ll); b=max(b, 1ll); ans+=max(b-2, 0ll); b=min(b, 2ll); --a; --b; ++ile[a][b]; } rep(i, n) { --ile[i][0]; --ile[i][1]; if(ile[i][0]<0 && ile[i][1]>0) { ll p=min(abs(ile[i][0]), ile[i][1]); ans+=p; ile[i][0]+=p; ile[i][1]-=p; } if(ile[i][0]>0 && ile[i][1]<0) { ll p=min(abs(ile[i][1]), ile[i][0]); ans+=p; ile[i][0]-=p; ile[i][1]+=p; } ans+=abs(ile[i][0]); ans+=abs(ile[i][1]); ile[i+1][0]+=ile[i][0]; ile[i+1][1]+=ile[i][1]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...