# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282896 |
2020-08-25T06:48:35 Z |
임성재(#5752) |
Iqea (innopolis2018_final_C) |
C++17 |
|
1262 ms |
27128 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n;
int x[100010];
int y[100010];
vector<int> g[100010];
map<pii, int> m;
int chk[100010];
int ans[100010];
int main() {
fast;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> x[i] >> y[i];
ans[i] = inf;
m[mp(x[i], y[i])] = i;
}
for(int i=1; i<=n; i++) {
if(m.find(mp(x[i]+1, y[i])) != m.end()) {
int j = m[mp(x[i]+1, y[i])];
g[i].eb(j);
g[j].eb(i);
}
if(m.find(mp(x[i]-1, y[i])) != m.end()) {
int j = m[mp(x[i]-1, y[i])];
g[i].eb(j);
g[j].eb(i);
}
if(m.find(mp(x[i], y[i]+1)) != m.end()) {
int j = m[mp(x[i], y[i]+1)];
g[i].eb(j);
g[j].eb(i);
}
if(m.find(mp(x[i], y[i]-1)) != m.end()) {
int j = m[mp(x[i], y[i]-1)];
g[i].eb(j);
g[j].eb(i);
}
}
int q;
cin >> q;
while(q--) {
int t, x, y;
cin >> t >> x >> y;
int k = m[mp(x, y)];
if(t == 1) {
if(chk[k]) continue;
chk[k] = true;
queue<int> Q;
int d[5010] = {};
Q.em(k);
d[k] = 1;
while(Q.size()) {
int x = Q.front();
Q.pop();
ans[x] = min(ans[x], d[x] - 1);
for(auto i : g[x]) {
if(d[i]) continue;
d[i] = d[x] + 1;
Q.em(i);
}
}
}
else {
if(ans[k] == inf) cout << "-1\n";
else cout << ans[k] << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
530 ms |
3352 KB |
Output is correct |
5 |
Correct |
552 ms |
3384 KB |
Output is correct |
6 |
Correct |
626 ms |
3596 KB |
Output is correct |
7 |
Correct |
488 ms |
3448 KB |
Output is correct |
8 |
Correct |
474 ms |
3320 KB |
Output is correct |
9 |
Correct |
493 ms |
3448 KB |
Output is correct |
10 |
Correct |
468 ms |
3320 KB |
Output is correct |
11 |
Correct |
474 ms |
3320 KB |
Output is correct |
12 |
Correct |
507 ms |
3448 KB |
Output is correct |
13 |
Correct |
496 ms |
3448 KB |
Output is correct |
14 |
Correct |
498 ms |
3452 KB |
Output is correct |
15 |
Correct |
482 ms |
3320 KB |
Output is correct |
16 |
Correct |
543 ms |
3340 KB |
Output is correct |
17 |
Correct |
553 ms |
3328 KB |
Output is correct |
18 |
Correct |
491 ms |
3320 KB |
Output is correct |
19 |
Correct |
503 ms |
3320 KB |
Output is correct |
20 |
Correct |
505 ms |
3336 KB |
Output is correct |
21 |
Correct |
534 ms |
3448 KB |
Output is correct |
22 |
Correct |
531 ms |
3324 KB |
Output is correct |
23 |
Correct |
537 ms |
3328 KB |
Output is correct |
24 |
Correct |
491 ms |
3428 KB |
Output is correct |
25 |
Correct |
499 ms |
3328 KB |
Output is correct |
26 |
Correct |
504 ms |
3328 KB |
Output is correct |
27 |
Correct |
441 ms |
3324 KB |
Output is correct |
28 |
Correct |
483 ms |
3304 KB |
Output is correct |
29 |
Correct |
473 ms |
3320 KB |
Output is correct |
30 |
Correct |
456 ms |
3320 KB |
Output is correct |
31 |
Correct |
426 ms |
3320 KB |
Output is correct |
32 |
Correct |
446 ms |
3320 KB |
Output is correct |
33 |
Correct |
469 ms |
3320 KB |
Output is correct |
34 |
Correct |
401 ms |
3320 KB |
Output is correct |
35 |
Correct |
432 ms |
3448 KB |
Output is correct |
36 |
Correct |
442 ms |
3320 KB |
Output is correct |
37 |
Correct |
450 ms |
3324 KB |
Output is correct |
38 |
Correct |
446 ms |
3448 KB |
Output is correct |
39 |
Correct |
413 ms |
3320 KB |
Output is correct |
40 |
Correct |
441 ms |
3316 KB |
Output is correct |
41 |
Correct |
490 ms |
3576 KB |
Output is correct |
42 |
Correct |
492 ms |
3328 KB |
Output is correct |
43 |
Correct |
445 ms |
3320 KB |
Output is correct |
44 |
Correct |
470 ms |
3448 KB |
Output is correct |
45 |
Correct |
500 ms |
3576 KB |
Output is correct |
46 |
Correct |
478 ms |
3448 KB |
Output is correct |
47 |
Correct |
542 ms |
3576 KB |
Output is correct |
48 |
Correct |
578 ms |
3440 KB |
Output is correct |
49 |
Correct |
588 ms |
3576 KB |
Output is correct |
50 |
Correct |
619 ms |
3596 KB |
Output is correct |
51 |
Correct |
615 ms |
3712 KB |
Output is correct |
52 |
Correct |
563 ms |
3448 KB |
Output is correct |
53 |
Correct |
556 ms |
3448 KB |
Output is correct |
54 |
Correct |
570 ms |
3556 KB |
Output is correct |
55 |
Correct |
571 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
530 ms |
3352 KB |
Output is correct |
5 |
Correct |
552 ms |
3384 KB |
Output is correct |
6 |
Correct |
626 ms |
3596 KB |
Output is correct |
7 |
Correct |
488 ms |
3448 KB |
Output is correct |
8 |
Correct |
474 ms |
3320 KB |
Output is correct |
9 |
Correct |
493 ms |
3448 KB |
Output is correct |
10 |
Correct |
468 ms |
3320 KB |
Output is correct |
11 |
Correct |
474 ms |
3320 KB |
Output is correct |
12 |
Correct |
507 ms |
3448 KB |
Output is correct |
13 |
Correct |
496 ms |
3448 KB |
Output is correct |
14 |
Correct |
498 ms |
3452 KB |
Output is correct |
15 |
Correct |
482 ms |
3320 KB |
Output is correct |
16 |
Correct |
543 ms |
3340 KB |
Output is correct |
17 |
Correct |
553 ms |
3328 KB |
Output is correct |
18 |
Correct |
491 ms |
3320 KB |
Output is correct |
19 |
Correct |
503 ms |
3320 KB |
Output is correct |
20 |
Correct |
505 ms |
3336 KB |
Output is correct |
21 |
Correct |
534 ms |
3448 KB |
Output is correct |
22 |
Correct |
531 ms |
3324 KB |
Output is correct |
23 |
Correct |
537 ms |
3328 KB |
Output is correct |
24 |
Correct |
491 ms |
3428 KB |
Output is correct |
25 |
Correct |
499 ms |
3328 KB |
Output is correct |
26 |
Correct |
504 ms |
3328 KB |
Output is correct |
27 |
Correct |
441 ms |
3324 KB |
Output is correct |
28 |
Correct |
483 ms |
3304 KB |
Output is correct |
29 |
Correct |
473 ms |
3320 KB |
Output is correct |
30 |
Correct |
456 ms |
3320 KB |
Output is correct |
31 |
Correct |
426 ms |
3320 KB |
Output is correct |
32 |
Correct |
446 ms |
3320 KB |
Output is correct |
33 |
Correct |
469 ms |
3320 KB |
Output is correct |
34 |
Correct |
401 ms |
3320 KB |
Output is correct |
35 |
Correct |
432 ms |
3448 KB |
Output is correct |
36 |
Correct |
442 ms |
3320 KB |
Output is correct |
37 |
Correct |
450 ms |
3324 KB |
Output is correct |
38 |
Correct |
446 ms |
3448 KB |
Output is correct |
39 |
Correct |
413 ms |
3320 KB |
Output is correct |
40 |
Correct |
441 ms |
3316 KB |
Output is correct |
41 |
Correct |
490 ms |
3576 KB |
Output is correct |
42 |
Correct |
492 ms |
3328 KB |
Output is correct |
43 |
Correct |
445 ms |
3320 KB |
Output is correct |
44 |
Correct |
470 ms |
3448 KB |
Output is correct |
45 |
Correct |
500 ms |
3576 KB |
Output is correct |
46 |
Correct |
478 ms |
3448 KB |
Output is correct |
47 |
Correct |
542 ms |
3576 KB |
Output is correct |
48 |
Correct |
578 ms |
3440 KB |
Output is correct |
49 |
Correct |
588 ms |
3576 KB |
Output is correct |
50 |
Correct |
619 ms |
3596 KB |
Output is correct |
51 |
Correct |
615 ms |
3712 KB |
Output is correct |
52 |
Correct |
563 ms |
3448 KB |
Output is correct |
53 |
Correct |
556 ms |
3448 KB |
Output is correct |
54 |
Correct |
570 ms |
3556 KB |
Output is correct |
55 |
Correct |
571 ms |
3420 KB |
Output is correct |
56 |
Correct |
1262 ms |
3932 KB |
Output is correct |
57 |
Correct |
1246 ms |
3832 KB |
Output is correct |
58 |
Correct |
1244 ms |
3832 KB |
Output is correct |
59 |
Correct |
899 ms |
3564 KB |
Output is correct |
60 |
Correct |
1004 ms |
3640 KB |
Output is correct |
61 |
Correct |
1068 ms |
3704 KB |
Output is correct |
62 |
Correct |
906 ms |
3704 KB |
Output is correct |
63 |
Correct |
957 ms |
3832 KB |
Output is correct |
64 |
Correct |
1044 ms |
3708 KB |
Output is correct |
65 |
Correct |
1004 ms |
3632 KB |
Output is correct |
66 |
Correct |
998 ms |
3704 KB |
Output is correct |
67 |
Correct |
1018 ms |
3696 KB |
Output is correct |
68 |
Correct |
984 ms |
3576 KB |
Output is correct |
69 |
Correct |
1020 ms |
3660 KB |
Output is correct |
70 |
Correct |
950 ms |
3704 KB |
Output is correct |
71 |
Correct |
733 ms |
3492 KB |
Output is correct |
72 |
Correct |
1078 ms |
3796 KB |
Output is correct |
73 |
Correct |
1134 ms |
3576 KB |
Output is correct |
74 |
Correct |
971 ms |
3576 KB |
Output is correct |
75 |
Correct |
1020 ms |
3752 KB |
Output is correct |
76 |
Correct |
884 ms |
3804 KB |
Output is correct |
77 |
Correct |
936 ms |
3832 KB |
Output is correct |
78 |
Correct |
929 ms |
3704 KB |
Output is correct |
79 |
Correct |
896 ms |
3576 KB |
Output is correct |
80 |
Correct |
1048 ms |
3720 KB |
Output is correct |
81 |
Correct |
919 ms |
3760 KB |
Output is correct |
82 |
Correct |
1006 ms |
3852 KB |
Output is correct |
83 |
Correct |
1022 ms |
3704 KB |
Output is correct |
84 |
Correct |
904 ms |
3576 KB |
Output is correct |
85 |
Correct |
990 ms |
3864 KB |
Output is correct |
86 |
Correct |
1006 ms |
3832 KB |
Output is correct |
87 |
Correct |
956 ms |
3904 KB |
Output is correct |
88 |
Correct |
1181 ms |
3748 KB |
Output is correct |
89 |
Correct |
1216 ms |
3836 KB |
Output is correct |
90 |
Correct |
1256 ms |
3832 KB |
Output is correct |
91 |
Correct |
1250 ms |
3860 KB |
Output is correct |
92 |
Correct |
1227 ms |
4088 KB |
Output is correct |
93 |
Correct |
1139 ms |
3832 KB |
Output is correct |
94 |
Correct |
1119 ms |
3960 KB |
Output is correct |
95 |
Correct |
1141 ms |
3960 KB |
Output is correct |
96 |
Correct |
1128 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
245 ms |
26764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
312 ms |
27128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
530 ms |
3352 KB |
Output is correct |
5 |
Correct |
552 ms |
3384 KB |
Output is correct |
6 |
Correct |
626 ms |
3596 KB |
Output is correct |
7 |
Correct |
488 ms |
3448 KB |
Output is correct |
8 |
Correct |
474 ms |
3320 KB |
Output is correct |
9 |
Correct |
493 ms |
3448 KB |
Output is correct |
10 |
Correct |
468 ms |
3320 KB |
Output is correct |
11 |
Correct |
474 ms |
3320 KB |
Output is correct |
12 |
Correct |
507 ms |
3448 KB |
Output is correct |
13 |
Correct |
496 ms |
3448 KB |
Output is correct |
14 |
Correct |
498 ms |
3452 KB |
Output is correct |
15 |
Correct |
482 ms |
3320 KB |
Output is correct |
16 |
Correct |
543 ms |
3340 KB |
Output is correct |
17 |
Correct |
553 ms |
3328 KB |
Output is correct |
18 |
Correct |
491 ms |
3320 KB |
Output is correct |
19 |
Correct |
503 ms |
3320 KB |
Output is correct |
20 |
Correct |
505 ms |
3336 KB |
Output is correct |
21 |
Correct |
534 ms |
3448 KB |
Output is correct |
22 |
Correct |
531 ms |
3324 KB |
Output is correct |
23 |
Correct |
537 ms |
3328 KB |
Output is correct |
24 |
Correct |
491 ms |
3428 KB |
Output is correct |
25 |
Correct |
499 ms |
3328 KB |
Output is correct |
26 |
Correct |
504 ms |
3328 KB |
Output is correct |
27 |
Correct |
441 ms |
3324 KB |
Output is correct |
28 |
Correct |
483 ms |
3304 KB |
Output is correct |
29 |
Correct |
473 ms |
3320 KB |
Output is correct |
30 |
Correct |
456 ms |
3320 KB |
Output is correct |
31 |
Correct |
426 ms |
3320 KB |
Output is correct |
32 |
Correct |
446 ms |
3320 KB |
Output is correct |
33 |
Correct |
469 ms |
3320 KB |
Output is correct |
34 |
Correct |
401 ms |
3320 KB |
Output is correct |
35 |
Correct |
432 ms |
3448 KB |
Output is correct |
36 |
Correct |
442 ms |
3320 KB |
Output is correct |
37 |
Correct |
450 ms |
3324 KB |
Output is correct |
38 |
Correct |
446 ms |
3448 KB |
Output is correct |
39 |
Correct |
413 ms |
3320 KB |
Output is correct |
40 |
Correct |
441 ms |
3316 KB |
Output is correct |
41 |
Correct |
490 ms |
3576 KB |
Output is correct |
42 |
Correct |
492 ms |
3328 KB |
Output is correct |
43 |
Correct |
445 ms |
3320 KB |
Output is correct |
44 |
Correct |
470 ms |
3448 KB |
Output is correct |
45 |
Correct |
500 ms |
3576 KB |
Output is correct |
46 |
Correct |
478 ms |
3448 KB |
Output is correct |
47 |
Correct |
542 ms |
3576 KB |
Output is correct |
48 |
Correct |
578 ms |
3440 KB |
Output is correct |
49 |
Correct |
588 ms |
3576 KB |
Output is correct |
50 |
Correct |
619 ms |
3596 KB |
Output is correct |
51 |
Correct |
615 ms |
3712 KB |
Output is correct |
52 |
Correct |
563 ms |
3448 KB |
Output is correct |
53 |
Correct |
556 ms |
3448 KB |
Output is correct |
54 |
Correct |
570 ms |
3556 KB |
Output is correct |
55 |
Correct |
571 ms |
3420 KB |
Output is correct |
56 |
Correct |
1262 ms |
3932 KB |
Output is correct |
57 |
Correct |
1246 ms |
3832 KB |
Output is correct |
58 |
Correct |
1244 ms |
3832 KB |
Output is correct |
59 |
Correct |
899 ms |
3564 KB |
Output is correct |
60 |
Correct |
1004 ms |
3640 KB |
Output is correct |
61 |
Correct |
1068 ms |
3704 KB |
Output is correct |
62 |
Correct |
906 ms |
3704 KB |
Output is correct |
63 |
Correct |
957 ms |
3832 KB |
Output is correct |
64 |
Correct |
1044 ms |
3708 KB |
Output is correct |
65 |
Correct |
1004 ms |
3632 KB |
Output is correct |
66 |
Correct |
998 ms |
3704 KB |
Output is correct |
67 |
Correct |
1018 ms |
3696 KB |
Output is correct |
68 |
Correct |
984 ms |
3576 KB |
Output is correct |
69 |
Correct |
1020 ms |
3660 KB |
Output is correct |
70 |
Correct |
950 ms |
3704 KB |
Output is correct |
71 |
Correct |
733 ms |
3492 KB |
Output is correct |
72 |
Correct |
1078 ms |
3796 KB |
Output is correct |
73 |
Correct |
1134 ms |
3576 KB |
Output is correct |
74 |
Correct |
971 ms |
3576 KB |
Output is correct |
75 |
Correct |
1020 ms |
3752 KB |
Output is correct |
76 |
Correct |
884 ms |
3804 KB |
Output is correct |
77 |
Correct |
936 ms |
3832 KB |
Output is correct |
78 |
Correct |
929 ms |
3704 KB |
Output is correct |
79 |
Correct |
896 ms |
3576 KB |
Output is correct |
80 |
Correct |
1048 ms |
3720 KB |
Output is correct |
81 |
Correct |
919 ms |
3760 KB |
Output is correct |
82 |
Correct |
1006 ms |
3852 KB |
Output is correct |
83 |
Correct |
1022 ms |
3704 KB |
Output is correct |
84 |
Correct |
904 ms |
3576 KB |
Output is correct |
85 |
Correct |
990 ms |
3864 KB |
Output is correct |
86 |
Correct |
1006 ms |
3832 KB |
Output is correct |
87 |
Correct |
956 ms |
3904 KB |
Output is correct |
88 |
Correct |
1181 ms |
3748 KB |
Output is correct |
89 |
Correct |
1216 ms |
3836 KB |
Output is correct |
90 |
Correct |
1256 ms |
3832 KB |
Output is correct |
91 |
Correct |
1250 ms |
3860 KB |
Output is correct |
92 |
Correct |
1227 ms |
4088 KB |
Output is correct |
93 |
Correct |
1139 ms |
3832 KB |
Output is correct |
94 |
Correct |
1119 ms |
3960 KB |
Output is correct |
95 |
Correct |
1141 ms |
3960 KB |
Output is correct |
96 |
Correct |
1128 ms |
3704 KB |
Output is correct |
97 |
Runtime error |
245 ms |
26764 KB |
Execution killed with signal 11 |
98 |
Halted |
0 ms |
0 KB |
- |