Submission #1292102

#TimeUsernameProblemLanguageResultExecution timeMemory
1292102wedonttalkanymoreCoin Collecting (JOI19_ho_t4)C++20
100 / 100
33 ms5140 KiB
#include <bits/stdc++.h> /* Ngay hay dem Voi troi giac mo em dem */ using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19; int n, x[N], y[N]; int pre[N][2]; signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n; int ans = 0; for (int i = 1; i <= 2 * n; i++) { cin >> x[i] >> y[i]; if (x[i] >= n) { ans += x[i] - n; x[i] = n; } else if (x[i] < 1) { ans += 1 - x[i]; x[i] = 1; } if (y[i] >= 2) { ans += y[i] - 2; y[i] = 2; } else if (y[i] < 1) { ans += 1 - y[i]; y[i] = 1; } pre[x[i]][y[i] - 1]++; } for (int i = 1; i <= n; i++) { pre[i][0]--, pre[i][1]--; if (pre[i][0] * pre[i][1] < 0) { if (pre[i][0] < 0) { int val = min(abs(pre[i][0]), pre[i][1]); pre[i][0] += val; pre[i][1] -= val; ans += val; } if (pre[i][1] < 0) { int val = min(abs(pre[i][1]), pre[i][0]); pre[i][0] -= val; pre[i][1] += val; ans += val; } } ans += abs(pre[i][0]) + abs(pre[i][1]); pre[i + 1][0] += pre[i][0]; pre[i + 1][1] += pre[i][1]; } cout << ans; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...