Submission #782614

#TimeUsernameProblemLanguageResultExecution timeMemory
782614mychecksedadCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms212 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() const int N = 1e6+100, M = 1e5+10, K = 20; ll n, a[N][2], ans = 0; void solve(){ cin >> n; deque<pair<ll,ll>> up, down; for(int i = 0; i < 2*n; ++i){ ll x, y; cin >> x >> y; if(y >= 2) up.pb({x, y}), ans += y-2; else down.pb({x, y}), ans += abs(1-y); } sort(all(up)); sort(all(down)); if(size(up) < size(down)) swap(up, down); int i = 0; while(size(up) > size(down)){ if(i%2) down.pb(up.back()), up.pop_back(), ans++; else down.pb(up.front()), up.pop_front(), ans++; i++; } sort(all(up)); sort(all(down)); for(ll i = 0; i < n; ++i){ ans += abs(i + 1 - up[i].first); ans += abs(i + 1 - down[i].first); // cout << up[i].first << ' ' << up[i].second << '\n'; // cout << down[i].first << ' ' << down[i].second << '\n'; } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:49:14: warning: unused variable 'aa' [-Wunused-variable]
   49 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...