Submission #411639

#TimeUsernameProblemLanguageResultExecution timeMemory
411639albertolg101Wombats (IOI13_wombats)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "wombats.h" using namespace std; using pii = pair<long long, long long>; const long long INF = 1e12; int n, m; vector<vector<long long>> h(5001, vector<long long> (201)), v = h, dp = h; bool sol = false; void init(int R, int C, int H[5000][200], int V[5000][200]) { n = R, m = C; for(int i = 0 ; i < R ; i++) { for(int j = 0 ; j < C - 1 ; j++) { h[i][j] = H[i][j]; } } for(int i = 0 ; i < R - 1 ; i++) { for(int j = 0 ; j < C ; j++) { v[i][j] = V[i][j]; } } } void changeH(int P, int Q, int W) { h[P][Q] = W; sol = false; } void changeV(int P, int Q, int W) { v[P][Q] = W; sol = false; } int escape(int V1, int V2) { for(int i = 0 ; i < m ; i++) { dp[n-1][i] = INF; } dp[n-1][V2] = 0; for(int i = n - 1 ; i >= 0 ; i--) { set<pii> s; for(int j = 0 ; j < m ; j++) s.insert({dp[i][j], j}); while(s.size()) { long long j, dist, dist2; tie(dist, j) = *s.begin(); dist2 = dist; s.erase(s.begin()); if(dp[i][j] < dist) continue; for(int k = j + 1 ; k < m ; k++) { if(dp[i][k] > dist + h[i][k-1]) { dp[i][k] = dist + h[i][k-1]; dist += h[i][k-1]; } else break; } for(int k = j - 1 ; k >= 0 ; k--) { dist2 += h[i][k]; if(dp[i][k] > dist2 + h[i][k]) { dp[i][k] = dist2 + h[i][k]; } else break; } } for(int j = 0 ; j < m and i != 0; j++) { dp[i-1][j] = dp[i][j] + v[i-1][j]; } } /* for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m - 1; j++) { cout << h[i][j] << ' ' ; } cout << endl ; } cout << endl ; for(int i = 0 ; i < n - 1 ; i++) { for(int j = 0 ; j < m ; j++) { cout << v[i][j] << ' ' ; } cout << endl ; } cout << endl ; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { cout << dp[i][j] << ' ' ; } cout << endl; } */ return dp[0][V1]; } #define fail(s, x...) do { \ fprintf(stderr, s "\n", ## x); \ exit(1); \ } while(0) static int H[5000][200]; static int V[5000][200]; int main() { int R, C, E, P, Q, W, V1, V2, event, i, j; int res; FILE *f = fopen("wombats.in", "r"); if (!f) fail("Failed to open input file."); res = fscanf(f, "%d%d", &R, &C); for (i = 0; i < R; ++i) for (j = 0; j < C-1; ++j) res = fscanf(f, "%d", &H[i][j]); for (i = 0; i < R-1; ++i) for (j = 0; j < C; ++j) res = fscanf(f, "%d", &V[i][j]); init(R, C, H, V); res = fscanf(f, "%d", &E); for (i = 0; i < E; i++) { res = fscanf(f, "%d", &event); if (event == 1) { res = fscanf(f, "%d%d%d", &P, &Q, &W); changeH(P, Q, W); } else if (event == 2) { res = fscanf(f, "%d%d%d", &P, &Q, &W); changeV(P, Q, W); } else if (event == 3) { res = fscanf(f, "%d%d", &V1, &V2); printf("%d\n", escape(V1, V2)); } else fail("Invalid event type."); } fclose(f); return 0; }

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp: In function 'int main()':
wombats.cpp:146:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  146 |  int res;
      |      ^~~
/usr/bin/ld: /tmp/cc6wXCM9.o: in function `main':
wombats.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccF3Ffkb.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status