# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
129689 | 2019-07-13T04:48:30 Z | 김세빈(#3138) | 물병 (JOI14_bottle) | C++14 | 5000 ms | 41340 KB |
#include <bits/stdc++.h> using namespace std; struct edge{ int u, v, c; edge() {} edge(int u, int v, int c) : u(u), v(v), c(c) {} }; char B[2020][2020]; queue <int> Q; vector <edge> K; vector <int> V[202020]; int C[4040404], D[4040404], P[202020]; int X[202020], Y[202020], S[202020], E[202020]; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int n, m, k, q; int find(int p) { return p == P[p]? p : P[p] = find(P[p]); } void unite(int p, int q) { P[find(p)] = find(q); } int main() { int i, x, y, p, t, f; scanf("%d%d%d%d", &n, &m, &k, &q); for(i=0; i<n; i++){ scanf("%s", B[i]); } for(i=1; i<=k; i++){ scanf("%d%d", &x, &y); x --; y --; t = x * m + y; Q.push(t); C[t] = i; D[t] = 0; P[i] = i; } for(; !Q.empty(); ){ p = Q.front(); Q.pop(); x = p / m; y = p % m; for(i=0; i<4; i++){ x += dx[i]; y += dy[i]; if(0 <= x && x < n && 0 <= y && y < m && B[x][y] == '.'){ t = x * m + y; if(!C[t]) Q.push(t), C[t] = C[p], D[t] = D[p] + 1; else if(find(C[t]) != find(C[p])){ unite(C[t], C[p]); K.emplace_back(C[p], C[t], D[t] + D[p]); } } x -= dx[i]; y -= dy[i]; } } sort(K.begin(), K.end(), [&](edge &ea, edge &eb){ return ea.c < eb.c; }); for(i=1; i<=q; i++){ scanf("%d%d", X + i, Y + i); // S[i] = 0; E[i] = K.size() - 1; int j; for(j=1; j<=k; j++) P[j] = j; for(j=0; j<K.size(); j++){ unite(K[j].u, K[j].v); if(find(X[i]) == find(Y[i])) break; } if(j < K.size()) printf("%d\n", K[j].c); else printf("-1\n"); } /* for(; ; ){ for(i=1; i<=k; i++){ P[i] = i; } for(i=0; i<K.size(); i++){ V[i].clear(); } for(i=1, f=0; i<=q; i++){ if(S[i] <= E[i]){ V[S[i] + E[i] >> 1].push_back(i); f = 1; } } if(!f) break; for(i=0; i<K.size(); i++){ unite(K[i].u, K[i].v); for(int &t: V[i]){ if(find(X[t]) == find(Y[t])){ E[t] = (S[t] + E[t] >> 1) - 1; } else S[t] = (S[t] + E[t] >> 1) + 1; } } } for(i=1; i<=q; i++){ if(E[i] + 1 < K.size()) printf("%d\n", K[E[i] + 1].c); else printf("-1\n"); } */ return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 5368 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 10744 KB | Output is correct |
2 | Correct | 43 ms | 8952 KB | Output is correct |
3 | Correct | 400 ms | 40692 KB | Output is correct |
4 | Correct | 604 ms | 40740 KB | Output is correct |
5 | Correct | 668 ms | 41172 KB | Output is correct |
6 | Correct | 385 ms | 40568 KB | Output is correct |
7 | Correct | 623 ms | 40824 KB | Output is correct |
8 | Correct | 664 ms | 41052 KB | Output is correct |
9 | Correct | 768 ms | 41340 KB | Output is correct |
10 | Correct | 405 ms | 40568 KB | Output is correct |
11 | Correct | 562 ms | 40732 KB | Output is correct |
12 | Correct | 164 ms | 34008 KB | Output is correct |
13 | Correct | 217 ms | 33840 KB | Output is correct |
14 | Correct | 155 ms | 34004 KB | Output is correct |
15 | Correct | 212 ms | 33784 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 51 ms | 10764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5005 ms | 41240 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |