# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1077115 |
2024-08-27T00:57:01 Z |
pawned |
Toy (CEOI24_toy) |
C++17 |
|
1500 ms |
132576 KB |
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int dir1[8] = {-1, 1, 0, 0, 0, 0, 0, 0};
int dir2[8] = {0, 0, -1, 1, 0, 0, 0, 0};
int dir3[8] = {0, 0, 0, 0, -1, 1, 0, 0};
int dir4[8] = {0, 0, 0, 0, 0, 0, -1, 1};
int main() {
fastIO();
int R, C, K, L;
// K = horizontal width, L = vertical width
cin>>C>>R>>K>>L;
pair<ii, ii> start;
// {horizontal left coords, vertical top coords}
cin>>start.fi.se>>start.fi.fi>>start.se.se>>start.se.fi;
ii goal; // goal cell
vector<vector<char>> grid(R, vector<char>(C, '.'));
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cin>>grid[i][j];
if (grid[i][j] == '*')
goal = {i, j};
}
}
// prefix sums to check for filled
vector<vi> pfs1(R, vi(C + 1, 0)); // horizontal prefix sums
vector<vi> pfs2(R + 1, vi(C, 0)); // vertical prefix sums
for (int i = 0; i < R; i++) {
for (int j = 1; j <= C; j++) {
pfs1[i][j] = pfs1[i][j - 1];
if (grid[i][j - 1] == 'X')
pfs1[i][j]++;
}
}
for (int i = 0; i < C; i++) {
for (int j = 1; j <= R; j++) {
pfs2[j][i] = pfs2[j - 1][i];
if (grid[j - 1][i] == 'X')
pfs2[j][i]++;
}
}
/* cout<<"pfs1: "<<endl;
for (vi v : pfs1) {
for (int x : v)
cout<<x<<" ";
cout<<endl;
}
cout<<"pfs2: "<<endl;
for (vi v : pfs2) {
for (int x : v)
cout<<x<<" ";
cout<<endl;
}*/
set<pair<ii, ii>> visited;
queue<pair<ii, ii>> q;
visited.insert(start);
q.push(start);
while (!q.empty()) {
pair<ii, ii> x = q.front();
q.pop();
// cout<<"at ("<<x.fi.fi<<", "<<x.fi.se<<", "<<x.se.fi<<", "<<x.se.se<<")"<<endl;
for (int i = 0; i < 8; i++) {
pair<ii, ii> y = x; // new state
y.fi.fi += dir1[i];
y.fi.se += dir2[i];
y.se.fi += dir3[i];
y.se.se += dir4[i];
// cout<<"going to ("<<y.fi.fi<<", "<<y.fi.se<<", "<<y.se.fi<<", "<<y.se.se<<")"<<endl;
// check if state is possible
if (y.fi.fi < 0 || y.fi.fi >= R || y.fi.se < 0 || y.fi.se >= C - K + 1)
continue;
if (y.se.se < 0 || y.se.se >= C || y.se.fi < 0 || y.se.fi >= R - L + 1)
continue;
// check if they intersect
if (y.fi.fi < y.se.fi || y.fi.fi >= y.se.fi + L)
continue;
if (y.se.se < y.fi.se || y.se.se >= y.fi.se + K)
continue;
// state is in grid, check if none on it blocked
if (pfs1[y.fi.fi][y.fi.se + K] - pfs1[y.fi.fi][y.fi.se] > 0)
continue;
if (pfs2[y.se.fi + L][y.se.se] - pfs2[y.se.fi][y.se.se] > 0)
continue;
// if state is possible and unvisited, add to queue
if (visited.find(y) == visited.end()) {
q.push(y);
visited.insert(y);
}
}
}
// check if any of visited intersect at flag
bool found = false;
for (pair<ii, ii> p : visited) {
ii ins = {p.fi.fi, p.se.se};
if (ins == goal)
found = true;
}
if (found)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
796 KB |
Output is correct |
4 |
Correct |
291 ms |
20308 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
368 ms |
23632 KB |
Output is correct |
16 |
Correct |
301 ms |
20216 KB |
Output is correct |
17 |
Correct |
342 ms |
21992 KB |
Output is correct |
18 |
Correct |
416 ms |
26884 KB |
Output is correct |
19 |
Correct |
415 ms |
26588 KB |
Output is correct |
20 |
Correct |
426 ms |
26192 KB |
Output is correct |
21 |
Correct |
431 ms |
26964 KB |
Output is correct |
22 |
Correct |
399 ms |
26704 KB |
Output is correct |
23 |
Correct |
401 ms |
26196 KB |
Output is correct |
24 |
Correct |
153 ms |
11964 KB |
Output is correct |
25 |
Correct |
128 ms |
10720 KB |
Output is correct |
26 |
Correct |
116 ms |
9252 KB |
Output is correct |
27 |
Correct |
106 ms |
8528 KB |
Output is correct |
28 |
Correct |
90 ms |
7764 KB |
Output is correct |
29 |
Correct |
81 ms |
6996 KB |
Output is correct |
30 |
Correct |
80 ms |
7504 KB |
Output is correct |
31 |
Correct |
98 ms |
8784 KB |
Output is correct |
32 |
Correct |
48 ms |
4436 KB |
Output is correct |
33 |
Correct |
49 ms |
4940 KB |
Output is correct |
34 |
Correct |
121 ms |
8020 KB |
Output is correct |
35 |
Correct |
76 ms |
6900 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
22 ms |
2224 KB |
Output is correct |
38 |
Correct |
24 ms |
2312 KB |
Output is correct |
39 |
Correct |
21 ms |
2416 KB |
Output is correct |
40 |
Correct |
21 ms |
2388 KB |
Output is correct |
41 |
Correct |
24 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
796 KB |
Output is correct |
4 |
Correct |
291 ms |
20308 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
368 ms |
23632 KB |
Output is correct |
16 |
Correct |
301 ms |
20216 KB |
Output is correct |
17 |
Correct |
342 ms |
21992 KB |
Output is correct |
18 |
Correct |
416 ms |
26884 KB |
Output is correct |
19 |
Correct |
415 ms |
26588 KB |
Output is correct |
20 |
Correct |
426 ms |
26192 KB |
Output is correct |
21 |
Correct |
431 ms |
26964 KB |
Output is correct |
22 |
Correct |
399 ms |
26704 KB |
Output is correct |
23 |
Correct |
401 ms |
26196 KB |
Output is correct |
24 |
Correct |
153 ms |
11964 KB |
Output is correct |
25 |
Correct |
128 ms |
10720 KB |
Output is correct |
26 |
Correct |
116 ms |
9252 KB |
Output is correct |
27 |
Correct |
106 ms |
8528 KB |
Output is correct |
28 |
Correct |
90 ms |
7764 KB |
Output is correct |
29 |
Correct |
81 ms |
6996 KB |
Output is correct |
30 |
Correct |
80 ms |
7504 KB |
Output is correct |
31 |
Correct |
98 ms |
8784 KB |
Output is correct |
32 |
Correct |
48 ms |
4436 KB |
Output is correct |
33 |
Correct |
49 ms |
4940 KB |
Output is correct |
34 |
Correct |
121 ms |
8020 KB |
Output is correct |
35 |
Correct |
76 ms |
6900 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
22 ms |
2224 KB |
Output is correct |
38 |
Correct |
24 ms |
2312 KB |
Output is correct |
39 |
Correct |
21 ms |
2416 KB |
Output is correct |
40 |
Correct |
21 ms |
2388 KB |
Output is correct |
41 |
Correct |
24 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
46 ms |
4292 KB |
Output is correct |
48 |
Correct |
67 ms |
4592 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
133 ms |
10324 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Execution timed out |
1582 ms |
83364 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
60 ms |
5712 KB |
Output is correct |
4 |
Execution timed out |
1580 ms |
132576 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
796 KB |
Output is correct |
4 |
Correct |
291 ms |
20308 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
368 ms |
23632 KB |
Output is correct |
16 |
Correct |
301 ms |
20216 KB |
Output is correct |
17 |
Correct |
342 ms |
21992 KB |
Output is correct |
18 |
Correct |
416 ms |
26884 KB |
Output is correct |
19 |
Correct |
415 ms |
26588 KB |
Output is correct |
20 |
Correct |
426 ms |
26192 KB |
Output is correct |
21 |
Correct |
431 ms |
26964 KB |
Output is correct |
22 |
Correct |
399 ms |
26704 KB |
Output is correct |
23 |
Correct |
401 ms |
26196 KB |
Output is correct |
24 |
Correct |
153 ms |
11964 KB |
Output is correct |
25 |
Correct |
128 ms |
10720 KB |
Output is correct |
26 |
Correct |
116 ms |
9252 KB |
Output is correct |
27 |
Correct |
106 ms |
8528 KB |
Output is correct |
28 |
Correct |
90 ms |
7764 KB |
Output is correct |
29 |
Correct |
81 ms |
6996 KB |
Output is correct |
30 |
Correct |
80 ms |
7504 KB |
Output is correct |
31 |
Correct |
98 ms |
8784 KB |
Output is correct |
32 |
Correct |
48 ms |
4436 KB |
Output is correct |
33 |
Correct |
49 ms |
4940 KB |
Output is correct |
34 |
Correct |
121 ms |
8020 KB |
Output is correct |
35 |
Correct |
76 ms |
6900 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
22 ms |
2224 KB |
Output is correct |
38 |
Correct |
24 ms |
2312 KB |
Output is correct |
39 |
Correct |
21 ms |
2416 KB |
Output is correct |
40 |
Correct |
21 ms |
2388 KB |
Output is correct |
41 |
Correct |
24 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
46 ms |
4292 KB |
Output is correct |
48 |
Correct |
67 ms |
4592 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
133 ms |
10324 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Execution timed out |
1582 ms |
83364 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
796 KB |
Output is correct |
4 |
Correct |
291 ms |
20308 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
368 ms |
23632 KB |
Output is correct |
16 |
Correct |
301 ms |
20216 KB |
Output is correct |
17 |
Correct |
342 ms |
21992 KB |
Output is correct |
18 |
Correct |
416 ms |
26884 KB |
Output is correct |
19 |
Correct |
415 ms |
26588 KB |
Output is correct |
20 |
Correct |
426 ms |
26192 KB |
Output is correct |
21 |
Correct |
431 ms |
26964 KB |
Output is correct |
22 |
Correct |
399 ms |
26704 KB |
Output is correct |
23 |
Correct |
401 ms |
26196 KB |
Output is correct |
24 |
Correct |
153 ms |
11964 KB |
Output is correct |
25 |
Correct |
128 ms |
10720 KB |
Output is correct |
26 |
Correct |
116 ms |
9252 KB |
Output is correct |
27 |
Correct |
106 ms |
8528 KB |
Output is correct |
28 |
Correct |
90 ms |
7764 KB |
Output is correct |
29 |
Correct |
81 ms |
6996 KB |
Output is correct |
30 |
Correct |
80 ms |
7504 KB |
Output is correct |
31 |
Correct |
98 ms |
8784 KB |
Output is correct |
32 |
Correct |
48 ms |
4436 KB |
Output is correct |
33 |
Correct |
49 ms |
4940 KB |
Output is correct |
34 |
Correct |
121 ms |
8020 KB |
Output is correct |
35 |
Correct |
76 ms |
6900 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
22 ms |
2224 KB |
Output is correct |
38 |
Correct |
24 ms |
2312 KB |
Output is correct |
39 |
Correct |
21 ms |
2416 KB |
Output is correct |
40 |
Correct |
21 ms |
2388 KB |
Output is correct |
41 |
Correct |
24 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
46 ms |
4292 KB |
Output is correct |
48 |
Correct |
67 ms |
4592 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
133 ms |
10324 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Execution timed out |
1582 ms |
83364 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |