Submission #887068

#TimeUsernameProblemLanguageResultExecution timeMemory
887068stefanneaguCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms460 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int nmax = 3e5 + 1; int f[nmax][3]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, ans = 0; cin >> n; for(int i = 1; i <= 2 * n; i ++) { int a, b; cin >> a >> b; // cout << i << " "; // punem in cel mai apropiat loc if(a < 1) { //cout << "b mai mic "; ans += 1 - a; a = 1; } else if(a > n) { //cout << "b mai mare "; ans += a - n; a = n; } if(b < 1) { //cout << "a mai mic "; ans += 1 - b; b = 1; } else if(b > 2) { //cout << "a mai mare "; ans += b - 2; b = 2; } //cout << endl; f[a][b] ++; } /* for(int i = 1; i <= 2; i ++) { for(int j = 1; j <= n; j ++) { cout << f[i][j] << " "; } cout << endl; } */ for(int i = 1; i <= n; i ++) { for(int j = 1; j <= 2; j ++) { if(f[i][j] == 0) { int minn = 1e9, ni, nj; for(int x = 1; x <= n; x ++) { for(int y = 1; y <= 2; y ++) { if(f[x][y] > 1 && minn > abs(x - i) + abs(y - j)) { ni = x; nj = y; minn = abs(x - i) + abs(y - j); } } } f[i][j] ++; f[ni][nj] --; ans += minn; } } } cout << ans; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int32_t main()':
joi2019_ho_t4.cpp:63:19: warning: 'nj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |         f[ni][nj] --;
      |         ~~~~~~~~~~^~
joi2019_ho_t4.cpp:63:19: warning: 'ni' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...