답안 #1068054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068054 2024-08-21T06:58:22 Z sleepntsheep 웜뱃 (IOI13_wombats) C++17
76 / 100
11444 ms 30540 KB
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <cassert>
    using namespace std;
     
    #include "wombats.h"
    #pragma GCC optimize("O3,unroll-loops")
    #ifndef ROW
    #define ROW 5000
    #endif
     
    constexpr int B = 1000;
     
    int r, c, h[ROW][100], v[ROW + 1][100];
     
    int L[9999], R[9999], By[9999];
     
    int a[100][100][100];
     
    int ans[100][100];
     
    void calc(int blk) {
    	for (int ii = 0; ii < c; ++ii) {
    		static int dp[2][100];
    		/* find answer for (V1, V2) where V1 = ii */
    		memset(dp[0], 63, sizeof dp[0]);
    		dp[0][ii] = 0;
    		int I = 0;
     
    		for (int i = L[blk]; i <= R[blk]; ++i, I ^= 1) {
    			static int pre[100], suf[100], ph[100]; /* annoying ahh math */ 
    			ph[0] = 0;
    			for (int j = 0; j + 1 < c; ++j)
    				ph[j + 1] = ph[j] + h[i][j];
     
    			pre[0] = dp[I][0];
    			for (int j = 1; j < c; ++j) pre[j] = min(pre[j - 1], dp[I][j] - ph[j]);
    			suf[c - 1] = dp[I][c - 1] + ph[c - 1];
    			for (int j = c - 2; j >= 0; --j) suf[j] = min(suf[j + 1], dp[I][j] + ph[j]);
     
    			for (int j = 0; j < c; ++j)
    				dp[I][j] = min(ph[j] + pre[j], suf[j] - ph[j]);
    			for (int j = 0; j < c; ++j)
    				dp[!I][j] = dp[I][j] + v[i][j];
    		}
    		for (int jj = 0; jj < c; ++jj)
    			a[blk][ii][jj] = dp[I][jj];
    	}
    }
     
    void merg(int up[100][100], int down[100][100], int out[100][100]) {
    	static int buf[100][100];
    	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) {
    		buf[i][j] = 1e9;
    		for (int k = 0; k < c; ++k)
    			buf[i][j] = min({buf[i][j], up[i][k]+ down[k][j]});
    	}
    	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) out[i][j] = buf[i][j];
    }
     
    void changeH(int P, int Q, int W) {
    	h[P][Q] = W;
    	calc(By[P]);
    	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) ans[i][j] = a[0][i][j];
    	for (int i = 1; i * B < r; ++i)
    		merg(ans, a[i], ans);
    }
     
    void changeV(int P, int Q, int W) {
    	v[P][Q] = W;
    	calc(By[P]);
    	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) ans[i][j] = a[0][i][j];
    	for (int i = 1; i * B < r; ++i)
    		merg(ans, a[i], ans);
    }
     
    void init(int R, int C, int H[ROW][200], int V[ROW][200]) {
    	r = R, c = C;
    	for (int i = 0; i + 1 < r; ++i) for (int j = 0; j < c; ++j)
    		v[i][j] = V[i][j];
    	for (int i = 0 ; i < r; ++i) for (int j = 0; j + 1 < c; ++j)
    		h[i][j] = H[i][j];
     
     
    	for (int i = 0; i * B < r; ++i) {
    		L[i] = i * B;
    		::R[i] = min(r - 1, i * B + B - 1);
    		calc(i);
    		for (int j = L[i]; j <= ::R[i]; ++j) By[j] = i;
    	}
     
    	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) ans[i][j] = a[0][i][j];
    	for (int i = 1; i * B < r; ++i)
    		merg(ans, a[i], ans);
    }
     
    int escape(int V1, int V2) { return ans[V1][V2]; }
     

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6236 KB Output is correct
2 Correct 9 ms 6372 KB Output is correct
3 Correct 80 ms 7896 KB Output is correct
4 Correct 5 ms 6376 KB Output is correct
5 Correct 9 ms 6232 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 41 ms 1464 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 604 KB Output is correct
2 Correct 220 ms 604 KB Output is correct
3 Correct 198 ms 604 KB Output is correct
4 Correct 191 ms 772 KB Output is correct
5 Correct 219 ms 856 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1018 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12124 KB Output is correct
2 Correct 16 ms 12236 KB Output is correct
3 Correct 19 ms 12120 KB Output is correct
4 Correct 43 ms 12984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 756 KB Output is correct
2 Correct 228 ms 780 KB Output is correct
3 Correct 221 ms 764 KB Output is correct
4 Correct 193 ms 604 KB Output is correct
5 Correct 282 ms 600 KB Output is correct
6 Correct 15 ms 12120 KB Output is correct
7 Correct 15 ms 12224 KB Output is correct
8 Correct 29 ms 12056 KB Output is correct
9 Correct 52 ms 12956 KB Output is correct
10 Correct 8 ms 6232 KB Output is correct
11 Correct 5 ms 6236 KB Output is correct
12 Correct 85 ms 7796 KB Output is correct
13 Correct 5 ms 6236 KB Output is correct
14 Correct 8 ms 6236 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 39 ms 1360 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1042 ms 784 KB Output is correct
28 Correct 10970 ms 12768 KB Output is correct
29 Correct 11050 ms 14176 KB Output is correct
30 Correct 10286 ms 13992 KB Output is correct
31 Correct 11444 ms 18208 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 600 KB Output is correct
2 Correct 204 ms 828 KB Output is correct
3 Correct 194 ms 856 KB Output is correct
4 Correct 207 ms 860 KB Output is correct
5 Correct 228 ms 856 KB Output is correct
6 Correct 29 ms 12304 KB Output is correct
7 Correct 16 ms 12288 KB Output is correct
8 Correct 15 ms 12124 KB Output is correct
9 Correct 70 ms 13496 KB Output is correct
10 Correct 8 ms 6236 KB Output is correct
11 Correct 8 ms 6236 KB Output is correct
12 Correct 82 ms 8892 KB Output is correct
13 Correct 5 ms 6236 KB Output is correct
14 Correct 5 ms 6404 KB Output is correct
15 Runtime error 2233 ms 30540 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -