Submission #883083

#TimeUsernameProblemLanguageResultExecution timeMemory
883083vjudge1Coin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms348 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; int n; array<ll, 2> a[N]; void solve(){ cin >> n; for(int i = 1; i <= 2*n; ++i) cin >> a[i][0] >> a[i][1]; ll ans = 0; for(int i = 1; i <= 2*n; ++i){ if(a[i][1] >= 2){ ans += a[i][1] - 2; a[i][1] = 2; }else if(a[i][1] <= 1){ ans += 1 - a[i][1]; a[i][1] = 1; } if(a[i][0] <= 1){ ans += 1 - a[i][0]; a[i][0] = 1; }else if(a[i][0] >= n){ ans += a[i][0] - n; a[i][0] = n; } } sort(a+1, a+1+2*n); deque<int> X, Y; for(int i = 1; i <= 2*n; ++i){ if(a[i][1] == 1) X.pb(a[i][0]); else Y.pb(a[i][0]); } for(int i = 1; i <= n; ++i){ for(int rep = 0; rep < 2; ++rep){ if(!X.empty()){ if(Y.empty()){ ans += abs(X.front() - i); X.pop_front(); }else{ if(X.front() <= Y.front() + 1){ ans += abs(X.front() - i); X.pop_front(); }else{ ans += abs(Y.front() - i) + 1; Y.pop_front(); } } }else{ ans += abs(Y.front() - i) + 1; Y.pop_front(); } swap(X, Y); } } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

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