답안 #798500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798500 2023-07-30T19:05:49 Z QwertyPi 웜뱃 (IOI13_wombats) C++14
76 / 100
20000 ms 128948 KB
#include "wombats.h"
#include <bits/stdc++.h>

using namespace std;
const int R_MAX = 5000;
const int C_MAX = 200;
const int K = 10;
const int R_DIV_K_MUL_2 = 1024;
const int INF = 1 << 30;
int R, C, H[R_MAX][C_MAX], V[R_MAX][C_MAX];
int A[R_MAX / K][C_MAX][C_MAX];
int st[R_DIV_K_MUL_2][C_MAX][C_MAX], OPT[C_MAX][C_MAX];
bool chmin(int& x, int y){
	if(x > y){
		x = y; return true;
	}
	return false;
}


int DP[C_MAX][C_MAX];
void init(){
	for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) DP[i][j] = i == j ? 0 : INF;
}

void process(int row){
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			for(int k = j - 1; k >= 0; k--){
				if(!chmin(DP[i][k], DP[i][k + 1] + H[row][k])){
					break;
				}
			}
			for(int k = j + 1; k < C; k++){
				if(!chmin(DP[i][k], DP[i][k - 1] + H[row][k - 1])){
					break;
				}
			}
		}
	}
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			DP[i][j] += V[row][j];
		}
	}
}

int opt(int i, int j){
	if(i < 0 || j < 0) return 0;
	if(i >= C || j >= C) return C - 1;
	return OPT[i][j];
}

void st_merge(int v, int vl, int vr){
	for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = INF;
	for(int d = -C + 1; d <= C - 1; d++){
		for(int i = 0; i < C; i++){
			int j = i + d; if(j < 0 || j >= C) continue;
			for(int k = 0; k <= C - 1; k++){
				if(st[v][i][j] > st[vl][i][k] + st[vr][k][j]) OPT[i][j] = k, st[v][i][j] = st[vl][i][k] + st[vr][k][j];
			}
		}
	}
}

void st_update(int p, int v, int l, int r){
	if(l == r){
		for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = DP[i][j];
		return;
	}
	int m = (l + r) / 2;
	if(p <= m) st_update(p, v * 2 + 1, l, m);
	else st_update(p, v * 2 + 2, m + 1, r);
	st_merge(v, v * 2 + 1, v * 2 + 2);
}

void recalc(int part = -1){
	if(part == -1){
		for(int p = 0; p < R / K; p++) recalc(p);
		return;
	}
	init();
	for(int r = part * K; r < (part + 1) * K; r++){
		process(r);
	}
	st_update(part, 0, 0, R / K - 1);
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    ::R = (R + K - 1) / K * K, ::C = 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 = R; i < ::R; i++){
		for(int j = 0; j < C - 1; j++){
			::H[i][j] = INF;
		}
	}
	for(int i = 0; i < R - 1; i++){
		for(int j = 0; j < C; j++){
			::V[i][j] = V[i][j];
		}
	}
	recalc();
}

void changeH(int P, int Q, int W) {
	::H[P][Q] = W;
	recalc(P / K);
}

void changeV(int P, int Q, int W) {
	::V[P][Q] = W;
	recalc(P / K);
}

int escape(int V1, int V2) {
	return st[0][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 12372 KB Output is correct
2 Correct 6 ms 12372 KB Output is correct
3 Correct 57 ms 13976 KB Output is correct
4 Correct 6 ms 12432 KB Output is correct
5 Correct 6 ms 12372 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 55 ms 1680 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 401 ms 2312 KB Output is correct
2 Correct 359 ms 2396 KB Output is correct
3 Correct 440 ms 2432 KB Output is correct
4 Correct 456 ms 2428 KB Output is correct
5 Correct 459 ms 2412 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2313 ms 2508 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 10 ms 21056 KB Output is correct
3 Correct 11 ms 21112 KB Output is correct
4 Correct 37 ms 21868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 406 ms 2344 KB Output is correct
2 Correct 378 ms 2404 KB Output is correct
3 Correct 456 ms 2436 KB Output is correct
4 Correct 431 ms 2388 KB Output is correct
5 Correct 468 ms 2412 KB Output is correct
6 Correct 12 ms 21060 KB Output is correct
7 Correct 12 ms 21100 KB Output is correct
8 Correct 10 ms 21044 KB Output is correct
9 Correct 37 ms 21952 KB Output is correct
10 Correct 7 ms 12500 KB Output is correct
11 Correct 5 ms 12372 KB Output is correct
12 Correct 59 ms 14156 KB Output is correct
13 Correct 5 ms 12372 KB Output is correct
14 Correct 5 ms 12484 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 472 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 67 ms 1976 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2268 ms 2432 KB Output is correct
28 Correct 9735 ms 99660 KB Output is correct
29 Correct 7971 ms 82456 KB Output is correct
30 Correct 8261 ms 82624 KB Output is correct
31 Correct 8211 ms 101176 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 2432 KB Output is correct
2 Correct 342 ms 2396 KB Output is correct
3 Correct 447 ms 2396 KB Output is correct
4 Correct 440 ms 2436 KB Output is correct
5 Correct 452 ms 2412 KB Output is correct
6 Correct 11 ms 21000 KB Output is correct
7 Correct 11 ms 21056 KB Output is correct
8 Correct 11 ms 21072 KB Output is correct
9 Correct 40 ms 22328 KB Output is correct
10 Correct 6 ms 12372 KB Output is correct
11 Correct 6 ms 12372 KB Output is correct
12 Correct 66 ms 14512 KB Output is correct
13 Correct 6 ms 12500 KB Output is correct
14 Correct 6 ms 12372 KB Output is correct
15 Execution timed out 20062 ms 128948 KB Time limit exceeded
16 Halted 0 ms 0 KB -