Submission #915967

#TimeUsernameProblemLanguageResultExecution timeMemory
915967ReLiceCoin Collecting (JOI19_ho_t4)C++14
100 / 100
150 ms7472 KiB
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define vll vector<ll> #define bc back() #define arr array #define pll vector<pair<ll,ll>> using namespace std; template <class _T> bool chmin(_T &x, const _T &y){ bool f=0; if (x>y){x=y;f=1;} return f; } template <class _T> bool chmax(_T &x, const _T &y){ bool f=0; if (x<y){x=y;f=1;} return f; } //void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=2e18+7; const ll mod=1e9+7; const ll N=2e5+7; const ld eps=1e-9; void solve(){ ll i,j; ll n; cin>>n; ll a[n+1][3]; memset(a,0ll,sizeof(a)); ll sum=0; for(i=1;i<=2*n;i++){ ll x,y; cin>>x>>y; if(x<1){sum+=1-x;x=1;} if(x>n){sum+=x-n;x=n;} if(y<1){sum+=1-y;y=1;} if(y>2){sum+=y-2;y=2;} a[x][y-1]++; } deque<ll> v,v2; for(i=1;i<=n;i++){ if(a[i][0]==0)v.pb(i); if(a[i][1]==0)v2.pb(i); while(a[i][0]>1 && v.sz){ sum+=i-v[0]; a[i][0]--; v.pof; } while(a[i][1]>1 && v2.sz){ sum+=i-v2[0]; a[i][1]--; v2.pof; } while(v.sz && a[i][1]>1){ sum+=i-v[0]+1; a[i][1]--; v.pof; } while(v2.sz && a[i][0]>1){ sum+=i-v2[0]+1; a[i][0]--; v2.pof; } if(a[i][0]>1){ a[i+1][0]+=a[i][0]-1; sum+=a[i][0]-1; } if(a[i][1]>1){ a[i+1][1]+=a[i][1]-1; sum+=a[i][1]-1; } } cout<<sum<<endl; } signed main(){ //start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* */

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'void solve()':
joi2019_ho_t4.cpp:46:10: warning: unused variable 'j' [-Wunused-variable]
   46 |     ll i,j;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...