Submission #543316

#TimeUsernameProblemLanguageResultExecution timeMemory
543316Cookie197Coin Collecting (JOI19_ho_t4)C++17
100 / 100
57 ms4684 KiB
// Cookie197 // the people who invented competitive programming must be ******* crazy // why am i still here suffering while i can do something else more valuable? // WHY??? #pragma GCC optimize("O4,unroll-loops,no-stack-protector") #pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<iomanip> #include<math.h> #include<unordered_map> #include<numeric> #include<random> using namespace std; #define Why_does_competitive_programming_even_exist ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<ll,ll> #define pdd pair<double ,double> #define mp make_pair //#define mod 998244353 #define mod 1000000007 #define endl "\n" #define inf (ll)1e18 #define out(x) cout << #x << " = " << x <<endl; #define out2(a,b) cout<< #a << "[" << b << "]" << " = " << a[b] << endl; #define outp(x) cout << #x << " first = " << x.first << " second = " << x.second << endl ll n; vector<ll> c; ll cnt[3][100005]; ll ans,a,b,z; signed main(){ Why_does_competitive_programming_even_exist; cin>>n; for (int i=1;i<=2*n;i++) { ll x,y; cin>>x>>y; if (x<=1 && y>=2){ ans += (1-x) + (y-2); //a++; c.push_back(1); cnt[2][1]++; }else if (x<=1 && y<=1){ ans += (1-x) + (1-y); //b++; c.push_back(1); cnt[1][1]++; }else if (x>=n && y>=2){ ans += (x-n) + (y-2); //a++; c.push_back(n); cnt[2][n]++; }else if (x>=n && y<=1){ ans += (x-n) + (1-y); //b++; c.push_back(n); cnt[1][n]++; }else if (y>=2){ ans += (y-2); //a++; c.push_back(x); cnt[2][x]++; }else if (y<=1){ ans += (1-y); //b++; c.push_back(x); cnt[1][x]++; } } for (int i=1;i<=n;i++){ a += cnt[1][i]; b += cnt[2][i]; a--, b--; while(a+1<=0 && b-1>=0) a++, b--, ans++; while(a-1>=0 && b+1<=0) a--, b++, ans++; ans += abs(a) + abs(b); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...