Submission #117916

#TimeUsernameProblemLanguageResultExecution timeMemory
117916songcCoin Collecting (JOI19_ho_t4)C++14
100 / 100
73 ms2552 KiB
#include <bits/stdc++.h> #define MOD 1000000007 #define INF 1234567890 using namespace std; typedef long long LL; typedef pair<int, int> pii; int N; int A[2][101010]; LL ans; int main(){ int x, y, k; scanf("%d", &N); for (int i=1; i<=2*N; i++){ scanf("%d %d", &x, &y); if (y <= 1) ans += 1-y, y=1; else ans += y-2, y=2; if (x <= 1) ans += 1-x, x=1; else if (x >= N) ans += x-N, x=N; A[y-1][x]++; } for (int i=1; i<=N; i++){ if (A[0][i] < 1 && A[1][i] > 1){ k = min(1-A[0][i], A[1][i]-1); ans += k, A[0][i] += k, A[1][i] -= k; } if (A[1][i] < 1 && A[0][i] > 1){ k = min(1-A[1][i], A[0][i]-1); ans += k, A[1][i] += k, A[0][i] -= k; } A[0][i+1] += A[0][i]-1, ans += abs(A[0][i]-1); A[1][i+1] += A[1][i]-1, ans += abs(A[1][i]-1); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:16: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...