Submission #716510

#TimeUsernameProblemLanguageResultExecution timeMemory
716510BaytoroCoin Collecting (JOI19_ho_t4)C++17
100 / 100
58 ms6580 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl '\n' #define ll long long #define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9+9,N=2e5+5; int n,m,k; int a[N][2]; void solve(){ cin>>n; int ans=0; for(int i=0;i<2*n;i++){ int x,y;cin>>x>>y; if(x>n) ans+=(x-n),x=n; else if(x<1) ans+=(1-x),x=1; if(y>2) ans+=(y-2),y=2; else if(y<1) ans+=(1-y),y=1; x--,y--; a[x][y]++; } int l=0,r=0; for(int i=0;l<n || r<n;){ while(!a[i][0] && !a[i][1]) i++; if(a[i][0] && l<=i) ans+=(i-l++),a[i][0]--; else if(a[i][1] && r<=i) ans+=(i-r++),a[i][1]--; else if(a[i][0] && r<=i) ans+=(1+i-r++),a[i][0]--; else if(a[i][1] && l<=i) ans+=(1+i-l++),a[i][1]--; else{ a[i+1][0]+=a[i][0]; a[i+1][1]+=a[i][1]; ans+=(a[i][0]+a[i][1]); i++; } } cout<<ans; } main(){ //fopn("team"); ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } }

Compilation message (stderr)

joi2019_ho_t4.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      | ^~~~
joi2019_ho_t4.cpp: In function 'void fopn(std::string)':
joi2019_ho_t4.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...