Submission #97387

#TimeUsernameProblemLanguageResultExecution timeMemory
97387BruteforcemanCoin Collecting (JOI19_ho_t4)C++11
100 / 100
118 ms4068 KiB
#include "bits/stdc++.h" using namespace std; int x[200010], y[200010]; int cnt[3][100010]; vector <int> ball[3], cell[3]; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); long long ans = 0; for(int i = 1; i <= n+n; i++) { scanf("%d %d", &x[i], &y[i]); if(y[i] <= 1) { ans += abs(y[i] - 1); y[i] = 1; } else { ans += abs(y[i] - 2); y[i] = 2; } if(x[i] <= 1) { ans += abs(x[i] - 1); x[i] = 1; } else if (x[i] > n) { ans += abs(x[i] - n); x[i] = n; } cnt[y[i]][x[i]] += 1; } for(int i = 1; i <= n; i++) { cell[1].push_back(i); cell[2].push_back(i); for(int j = 1; j <= 2; j++) { int p = cnt[j][i]; while(p--) { ball[j].push_back(i); } } for(int j = 1; j <= 2; j++) { while(!cell[j].empty() && !ball[j].empty()) { int p = cell[j].back(); int q = ball[j].back(); ans += abs(p - q); cell[j].pop_back(); ball[j].pop_back(); } } for(int j = 1; j <= 2; j++) { while(!cell[3 - j].empty() && !ball[j].empty()) { int p = cell[3 - j].back(); int q = ball[j].back(); ans += abs(p - q) + 1; cell[3 - j].pop_back(); ball[j].pop_back(); } } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main(int, const char**)':
joi2019_ho_t4.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x[i], &y[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...