Submission #958785

#TimeUsernameProblemLanguageResultExecution timeMemory
958785raphaelpCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; vector<long long> X(N * 2), Y(N * 2); for (long long i = 0; i < 2 * N; i++) { cin >> X[i] >> Y[i]; } long long tot = 0; for (long long i = 0; i < 2 * N; i++) { if (Y[i] > 2) { tot += Y[i] - 2; Y[i] = 2; } } for (long long i = 0; i < 2 * N; i++) { if (X[i] > N) { tot += X[i] - N; X[i] = N; } } for (long long i = 0; i < 2 * N; i++) { if (Y[i] <= 0) { tot -= Y[i] - 1; Y[i] = 1; } } for (long long i = 0; i < 2 * N; i++) { if (X[i] <= 0) { tot -= X[i] - 1; X[i] = 1; } } vector<long long> one, two; for (long long i = 0; i < 2 * N; i++) { if (Y[i] == 1) one.push_back(X[i]); else two.push_back(X[i]); } sort(one.begin(), one.end()); sort(two.begin(), two.end()); one.push_back(1234567890); two.push_back(1234567890); long long buff1 = 0, buff2 = 0; for (long long i = 1; i <= N; i++) { int done1 = 0, done2 = 0; if (one[buff1] == i) { done1 = 1; buff1++; } if (two[buff2] == i) { done2 = 1; buff2++; } if (!done1) if (one[buff1] <= two[buff2]) { tot += abs(one[buff1] - i); buff1++; } else { tot += abs(two[buff2] - i) + 1; buff2++; } if (!done2) if (one[buff1] < two[buff2]) { tot += abs(one[buff1] - i) + 1; buff1++; } else { tot += abs(two[buff2] - i); buff2++; } } cout << tot; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:71:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   71 |         if (!done1)
      |            ^
joi2019_ho_t4.cpp:82:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   82 |         if (!done2)
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...