답안 #309225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309225 2020-10-02T22:38:13 Z sofapuden Mecho (IOI09_mecho) C++14
23 / 100
820 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second

int n, k;
bool ok = 0;

pair<int,int> sta, en;

vector<string> G;
vector<vector<int>> V;
vector<vector<int>> vis;

queue<pair<pair<int,int>,int>> Q;

auto cmp = [](pair<pair<int,int>,pair<int,int>> l, pair<pair<int,int>,pair<int,int>> r){
	if(l.f.f != r.f.f)return l.f.f < r.f.f;
	return l.f.s > r.f.s;
};
priority_queue<pair<pair<int,int>,pair<int,int>>, vector<pair<pair<int,int>,pair<int,int>>>, decltype(cmp)> PQ(cmp);

void fin(pair<pair<int,int>,pair<int,int>> now){
	if(vis[now.s.f][now.s.s] < now.f.s)return;
	vis[now.s.f][now.s.s] = now.f.s;
	if(now.s == en){cout << now.f.f << "\n";ok = 1;return;}
	if(now.s.f != n-1){
		if(V[now.s.f+1][now.s.s] > now.f.s/k-1){
			PQ.push({{min(V[now.s.f+1][now.s.s]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f+1,now.s.s}});
		}
	}
	if(now.s.s != n-1){
		if(V[now.s.f][now.s.s+1] > now.f.s/k-1){
			PQ.push({{min(V[now.s.f][now.s.s+1]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f,now.s.s+1}});
		}
	}
	
	if(now.s.f != 0){
		if(V[now.s.f-1][now.s.s] > now.f.s/k-1){
			PQ.push({{min(V[now.s.f-1][now.s.s]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f-1,now.s.s}});
		}
	}
	
	if(now.s.s != 0){
		if(V[now.s.f][now.s.s-1] > now.f.s/k-1){
			PQ.push({{min(V[now.s.f][now.s.s-1]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f,now.s.s-1}});
		}
	}

			
}
	
	
	

void search(pair<pair<int,int>,int> now){
	if(now.f.f < 0 || now.f.s < 0 || now.f.f >= n || now.f.s >= n)return;
	if(V[now.f.f][now.f.s] != -1)return;
	V[now.f.f][now.f.s] = now.s;
	Q.push({{now.f.f-1,now.f.s},now.s+1});
	Q.push({{now.f.f+1,now.f.s},now.s+1});
	Q.push({{now.f.f,now.f.s-1},now.s+1});
	Q.push({{now.f.f,now.f.s+1},now.s+1});
}

int main(){ 
	cin >> n >> k;
	G.resize(n);
	V.resize(n, vector<int> (n,-1));
	vis.resize(n, vector<int> (n, 100000));
	
	for(auto &x : G)cin >> x;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			if(G[i][j] == 'T')V[i][j] = -2;
			if(G[i][j] == 'M')sta = {i,j};
			if(G[i][j] == 'D'){en = {i,j};V[i][j] = 100000;}
			if(G[i][j] == 'H')Q.push({{i,j},0});
		}
	}
	while(!Q.empty()){
		auto x = Q.front();
		Q.pop();
		search(x);
	}
	//for(int i = 0; i < n; ++i){
		//for(int j = 0; j < n; ++j){
			//cout << V[i][j] << " ";
		//}
		//cout << "\n";
	//}
	PQ.push({{V[sta.f][sta.s]-1, 0},sta});
	while(!PQ.empty()){
		auto x = PQ.top();
		PQ.pop();
		//cout << x.f.f << " " << x.f.s << " " << x.s.f << " " << x.s.s << "\n";
		fin(x);
		if(ok)break;
	}
	if(!ok)cout << -1 << "\n";
}
	
	
	
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Runtime error 484 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Incorrect 1 ms 256 KB Output isn't correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Runtime error 644 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 670 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Incorrect 0 ms 256 KB Output isn't correct
16 Correct 0 ms 256 KB Output is correct
17 Incorrect 1 ms 384 KB Output isn't correct
18 Correct 1 ms 256 KB Output is correct
19 Incorrect 1 ms 384 KB Output isn't correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 1 ms 384 KB Output isn't correct
22 Correct 1 ms 384 KB Output is correct
23 Incorrect 1 ms 384 KB Output isn't correct
24 Correct 1 ms 384 KB Output is correct
25 Incorrect 1 ms 384 KB Output isn't correct
26 Correct 1 ms 384 KB Output is correct
27 Incorrect 1 ms 384 KB Output isn't correct
28 Correct 1 ms 384 KB Output is correct
29 Incorrect 1 ms 384 KB Output isn't correct
30 Correct 1 ms 384 KB Output is correct
31 Incorrect 1 ms 384 KB Output isn't correct
32 Correct 1 ms 384 KB Output is correct
33 Incorrect 13 ms 1536 KB Output isn't correct
34 Correct 12 ms 1536 KB Output is correct
35 Runtime error 436 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Incorrect 15 ms 1664 KB Output isn't correct
37 Correct 16 ms 1792 KB Output is correct
38 Runtime error 433 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Incorrect 20 ms 2176 KB Output isn't correct
40 Correct 21 ms 2220 KB Output is correct
41 Runtime error 434 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Incorrect 26 ms 2816 KB Output isn't correct
43 Correct 25 ms 2816 KB Output is correct
44 Runtime error 438 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Incorrect 31 ms 3328 KB Output isn't correct
46 Correct 30 ms 3328 KB Output is correct
47 Runtime error 449 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Incorrect 39 ms 3840 KB Output isn't correct
49 Correct 35 ms 3712 KB Output is correct
50 Runtime error 455 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Incorrect 46 ms 4224 KB Output isn't correct
52 Incorrect 44 ms 4480 KB Output isn't correct
53 Runtime error 465 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Incorrect 55 ms 4864 KB Output isn't correct
55 Incorrect 53 ms 4856 KB Output isn't correct
56 Runtime error 471 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Incorrect 62 ms 5500 KB Output isn't correct
58 Incorrect 63 ms 5496 KB Output isn't correct
59 Runtime error 477 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Incorrect 70 ms 6136 KB Output isn't correct
61 Incorrect 77 ms 6144 KB Output isn't correct
62 Runtime error 495 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Correct 132 ms 6136 KB Output is correct
64 Correct 133 ms 6136 KB Output is correct
65 Correct 137 ms 6136 KB Output is correct
66 Incorrect 125 ms 6392 KB Output isn't correct
67 Correct 112 ms 6264 KB Output is correct
68 Correct 94 ms 6392 KB Output is correct
69 Correct 94 ms 6392 KB Output is correct
70 Correct 90 ms 6392 KB Output is correct
71 Correct 89 ms 6392 KB Output is correct
72 Correct 77 ms 6392 KB Output is correct
73 Runtime error 481 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
74 Runtime error 701 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Runtime error 606 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
76 Runtime error 619 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
77 Runtime error 820 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
78 Runtime error 705 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
79 Runtime error 700 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Runtime error 701 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
81 Runtime error 717 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
82 Runtime error 704 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
83 Runtime error 744 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
84 Runtime error 674 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Runtime error 717 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
86 Runtime error 769 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
87 Runtime error 678 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
88 Runtime error 495 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
89 Runtime error 713 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Runtime error 505 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
91 Runtime error 497 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
92 Runtime error 504 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)