답안 #60367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60367 2018-07-24T02:38:07 Z spencercompton 웜뱃 (IOI13_wombats) C++17
55 / 100
20000 ms 263168 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
int bel[5000][200];
int rig[5000][200];
int r, c;
vector<vector<int> > get1(int a){
	// cout << "BEG " << endl;
	vector<vector<int> > ret;
	for(int i = 0; i<c; i++){
		vector<int> now;
		now.resize(c);
		int sum = 0;
		for(int j = i+1; j<c; j++){
			sum += rig[a][j-1];
			now[j] = sum;
		}
		sum = 0;
		for(int j = i-1; j>=0; j--){
			sum += rig[a][j];
			now[j] = sum;
		}
		ret.push_back(now);
	}
	// cout << "END " << endl;
	return ret;
}
vector<int> cur;
vector<vector<int> > a1;
vector<vector<int> > a2;
int beg;
int ro;
void go(int l, int r, int lo, int hi){
	if(l>r){
		return;
	}
	int m = (l+r)/2;
	int best = lo;
	int val = a1[beg][best] + a2[best][m] + bel[ro][best];
	for(int i = lo+1; i<hi; i++){
		int here = a1[beg][i] + a2[i][m] + bel[ro][i];
		if(here<val){
			val = here;
			best = i;
		}
	}
	cur[m] = val;
	go(l,m-1,lo,best);
	go(m+1,r,best,hi);
}
vector<vector<int> > comb(vector<vector<int> > a, vector<vector<int> > b){
	// vector<vector<int> > ret;
	// cur.resize(c);
	// a1 = a;
	// a2 = b;
	// for(int i = 0; i<c; i++){
	// 	beg = i;
	// 	go(0,c-1,0,c-1);
	// 	ret.push_back(cur);
	// }
	// return ret;

	vector<vector<int> > ret;
	cur.resize(c);
	a1 = a;
	a2 = b;
	for(int i = 0; i<c; i++){
		for(int k = 0; k<c; k++){
			int best = a1[i][0] + bel[ro][0] + a2[0][k];
			for(int j = 1; j<c; j++){
				best = min(best, a1[i][j] + bel[ro][j] + a2[j][k]);
			}
			// cout << "@ " << best << " " << i << " " << k << endl;
			cur[k] = best;
		}
		ret.push_back(cur);
	}
	return ret;
}
class Node{
public:
	int s, e;
	Node *l, *r;
	vector<vector<int> > ar;
	Node (int a, int b){
		s = a;
		e = b;
		if(s==e){
			ar = get1(s);
			l = NULL;
			r = NULL;
		}
		else{
			l = new Node(s,(s+e)/2);
			r = new Node((s+e)/2+1,e);
			ro = l->e;
			ar = comb(l->ar,r->ar);
		}
		// cout << "FOR " << a << " - " << b << endl;
		// for(int i = 0; i<c; i++){
		// 	for(int j = 0; j<c; j++){
		// 		// cout << i << " to " << j << " " << ar[i][j] << endl;
		// 	}
		// }
	}
	void upd(int ind){
		if(s==e){
			ar = get1(s);
			return;
		}
		if(ind<=(s+e)/2){
			l->upd(ind);
		}
		else{
			r->upd(ind);
		}
		ro = l->e;
		ar = comb(l->ar,r->ar);
	}
};
Node *t;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
	r = R;
	c = C;
	for(int i = 0; i<r; i++){
		for(int j =0 ; j<c; j++){
			if(i+1<r){
				bel[i][j] = V[i][j];
				// cout << bel[i][j] << " ";
			}
			if(j+1<c){
				rig[i][j] = H[i][j];
			}
		}
		// cout << endl;
	}
	t = new Node(0,r-1);
}
 
void changeH(int P, int Q, int W) {
	// cout << "UPDATE " << P << endl;
	rig[P][Q] = W;
	// t = new Node(0,c-1);
	t->upd(P);
}
 
void changeV(int P, int Q, int W) {
	// cout << "QED " << P << endl;
	bel[P][Q] = W;
	// t = new Node(0,c-1);
	t->upd(P);
}
 
int escape(int V1, int V2) {
	return t->ar[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]
  int res;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 9464 KB Output is correct
2 Correct 21 ms 9596 KB Output is correct
3 Correct 113 ms 12320 KB Output is correct
4 Correct 21 ms 12320 KB Output is correct
5 Correct 16 ms 12320 KB Output is correct
6 Correct 3 ms 12320 KB Output is correct
7 Correct 4 ms 12320 KB Output is correct
8 Correct 3 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12320 KB Output is correct
2 Correct 3 ms 12320 KB Output is correct
3 Correct 2 ms 12320 KB Output is correct
4 Correct 5 ms 12320 KB Output is correct
5 Correct 4 ms 12320 KB Output is correct
6 Correct 3 ms 12320 KB Output is correct
7 Correct 4 ms 12320 KB Output is correct
8 Correct 3 ms 12320 KB Output is correct
9 Correct 7 ms 12320 KB Output is correct
10 Correct 4 ms 12320 KB Output is correct
11 Correct 99 ms 12320 KB Output is correct
12 Correct 4 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1558 ms 12320 KB Output is correct
2 Correct 1250 ms 12320 KB Output is correct
3 Correct 1580 ms 12320 KB Output is correct
4 Correct 1223 ms 12320 KB Output is correct
5 Correct 1467 ms 12320 KB Output is correct
6 Correct 3 ms 12320 KB Output is correct
7 Correct 3 ms 12320 KB Output is correct
8 Correct 3 ms 12320 KB Output is correct
9 Correct 6078 ms 12320 KB Output is correct
10 Correct 3 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 19656 KB Output is correct
2 Correct 27 ms 19656 KB Output is correct
3 Correct 33 ms 19656 KB Output is correct
4 Correct 75 ms 20428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1615 ms 20428 KB Output is correct
2 Correct 1308 ms 20428 KB Output is correct
3 Correct 1530 ms 20428 KB Output is correct
4 Correct 1438 ms 20428 KB Output is correct
5 Correct 1199 ms 20428 KB Output is correct
6 Correct 39 ms 20428 KB Output is correct
7 Correct 29 ms 20428 KB Output is correct
8 Correct 44 ms 20428 KB Output is correct
9 Correct 84 ms 20428 KB Output is correct
10 Correct 23 ms 20428 KB Output is correct
11 Correct 23 ms 20428 KB Output is correct
12 Correct 122 ms 20428 KB Output is correct
13 Correct 26 ms 20428 KB Output is correct
14 Correct 21 ms 20428 KB Output is correct
15 Correct 4 ms 20428 KB Output is correct
16 Correct 3 ms 20428 KB Output is correct
17 Correct 4 ms 20428 KB Output is correct
18 Correct 3 ms 20428 KB Output is correct
19 Correct 5 ms 20428 KB Output is correct
20 Correct 4 ms 20428 KB Output is correct
21 Correct 5 ms 20428 KB Output is correct
22 Correct 2 ms 20428 KB Output is correct
23 Correct 4 ms 20428 KB Output is correct
24 Correct 4 ms 20428 KB Output is correct
25 Correct 188 ms 20428 KB Output is correct
26 Correct 5 ms 20428 KB Output is correct
27 Correct 6626 ms 20428 KB Output is correct
28 Execution timed out 20087 ms 263168 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1324 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -