Submission #122918

#TimeUsernameProblemLanguageResultExecution timeMemory
122918HideoCoin Collecting (JOI19_ho_t4)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define fr first #define sc second #define vi vector < int > #define vl vector < ll > #define pi pair < int, ll > #define pii pair < int, pi > #define vii vector < pi > const int N = 3e5 + 7; const int INF = 1e9 + 7; int a[N][3]; int n, ans; void close (int &v, int r){ if (v < 1){ ans += abs(1 - v); v = 1; } if (v > r){ ans += abs(r - v); v = r; } } main(){ cin >> n; int x, y; for (int i = 1; i <= 2 * n; i++){ scanf("%d%d", &x, &y); close(x, n); close(y, 2); a[x][y]++; } for (int i = 1; i <= n; i++){ if (min(a[i][1], a[i][2]) <= 0 && max(a[i][1], a[i][2]) > 0){ ans += abs(min(a[i][1], a[i][2])); if (a[i][1] < a[i][2]){ a[i][2] -= abs(a[i][1]); a[i][1] = 1; } else { a[i][1] -= abs(a[i][2]); a[i][2] = 1; } } a[i][1]--; a[i][2]--; ans += a[i][1] + a[i][2]; a[i + 1][1] += a[i][1]; a[i + 1][2] += a[i][2]; } cout << ans; }

Compilation message (stderr)

joi2019_ho_t4.cpp:32:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...