Submission #117832

#TimeUsernameProblemLanguageResultExecution timeMemory
117832JohnTitorCoin Collecting (JOI19_ho_t4)C++11
0 / 100
2 ms484 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for(int i=(j); i<=(k); i++) #define FFOR(i, j, k) for(int i=(j); i<(k); i++) #define DFOR(i, j, k) for(int i=(j); i>=(k); i--) #define bug(x) cerr<<#x<<" = "<<(x)<<'\n' #define pb push_back #define mp make_pair #define bit(s, i) (((s)>>(i))&1LL) #define mask(i) ((1LL<<(i))) #define builtin_popcount __builtin_popcountll #define __builtin_popcount __builtin_popcountll using ll=long long; using ld=long double; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2; template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;} template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);} template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);} template <typename T> inline void writeln(T x){write(x); putchar('\n');} #define taskname "Coin" int n; int x[200001]; int y[200001]; vector <int> top; vector <int> bot; int main(){ #ifdef Aria if(fopen(taskname".in", "r")) freopen(taskname".in", "r", stdin); #endif // Aria read(n); FOR(i, 1, n*2) read(x[i]), read(y[i]); ll ans=0; FOR(i, 1, n*2){ if(x[i]<1){ ans+=1-x[i]; x[i]=1; } else if(x[i]>n){ ans+=x[i]-n; x[i]=n; } if(y[i]<1){ ans+=1-y[i]; y[i]=1; } else if(y[i]>2){ ans+=y[i]-2; y[i]=2; } } FOR(i, 1, n*2) if(y[i]==1) top.pb(x[i]); else bot.pb(x[i]); sort(top.begin(), top.end()); reverse(top.begin(), top.end()); sort(bot.begin(), bot.end()); reverse(bot.begin(), bot.end()); FOR(i, 1, n){ int c0=0, c1=0; FOR(x, 1, 2){ if(top.empty()){ ans+=abs(bot.back()-i); bot.pop_back(); c1++; } else if(bot.empty()){ ans+=abs(top.back()-i); top.pop_back(); c0++; } else{ bool sw=0; if(top.back()<bot.back()){ ans+=abs(top.back()-i); top.pop_back(); c0++; } else if(top.back()>bot.back()){ ans+=abs(bot.back()-i); bot.pop_back(); c1++; } else{ if(c0){ ans+=abs(bot.back()-i); bot.pop_back(); c1++; } else{ ans+=abs(top.back()-i); top.pop_back(); c0++; } } } } if(c0==0||c1==0) ans++; } writeln(ans); }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:71:22: warning: unused variable 'sw' [-Wunused-variable]
                 bool sw=0;
                      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...