Submission #1077112

# Submission time Handle Problem Language Result Execution time Memory
1077112 2024-08-27T00:54:13 Z pawned Toy (CEOI24_toy) C++17
35 / 100
1104 ms 1048576 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;
	}*/
	vector<vector<vector<vector<bool>>>> vis(R, vector<vector<vector<bool>>>(C, vector<vector<bool>>(R, vector<bool>(C, false))));
	set<pair<ii, ii>> visited;
	queue<pair<ii, ii>> q;
	vis[start.fi.fi][start.fi.se][start.se.fi][start.se.se] = true;
	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 (!vis[y.fi.fi][y.fi.se][y.se.fi][y.se.se]) {
				q.push(y);
				vis[y.fi.fi][y.fi.se][y.se.fi][y.se.se] = true;
			}
		}
	}
	// check if any of visited intersect at flag
	bool found = false;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < R; k++) {
				for (int l = 0; l < C; l++) {
					if (vis[i][j][k][l]) {
//						cout<<"can do "<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
						ii ins = {i, l};
						if (ins == goal)
							found = true;
					}
				}
			}
		}
	}
	if (found)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 41 ms 9548 KB Output is correct
5 Correct 20 ms 9560 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 21 ms 9564 KB Output is correct
8 Correct 18 ms 9564 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 20 ms 9572 KB Output is correct
11 Correct 20 ms 9560 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 21 ms 9492 KB Output is correct
14 Correct 19 ms 9564 KB Output is correct
15 Correct 43 ms 9156 KB Output is correct
16 Correct 35 ms 7856 KB Output is correct
17 Correct 43 ms 8028 KB Output is correct
18 Correct 48 ms 9564 KB Output is correct
19 Correct 45 ms 9564 KB Output is correct
20 Correct 55 ms 9564 KB Output is correct
21 Correct 47 ms 9568 KB Output is correct
22 Correct 46 ms 9564 KB Output is correct
23 Correct 47 ms 9564 KB Output is correct
24 Correct 33 ms 9560 KB Output is correct
25 Correct 32 ms 9572 KB Output is correct
26 Correct 30 ms 9576 KB Output is correct
27 Correct 37 ms 9560 KB Output is correct
28 Correct 26 ms 9564 KB Output is correct
29 Correct 26 ms 9564 KB Output is correct
30 Correct 26 ms 8364 KB Output is correct
31 Correct 23 ms 8028 KB Output is correct
32 Correct 25 ms 8024 KB Output is correct
33 Correct 26 ms 9560 KB Output is correct
34 Correct 31 ms 8284 KB Output is correct
35 Correct 22 ms 8280 KB Output is correct
36 Correct 16 ms 8204 KB Output is correct
37 Correct 17 ms 7260 KB Output is correct
38 Correct 19 ms 8028 KB Output is correct
39 Correct 20 ms 7768 KB Output is correct
40 Correct 18 ms 8028 KB Output is correct
41 Correct 21 ms 8280 KB Output is correct
42 Correct 26 ms 9564 KB Output is correct
43 Correct 19 ms 9564 KB Output is correct
44 Correct 20 ms 9564 KB Output is correct
45 Correct 19 ms 9564 KB Output is correct
46 Correct 15 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 41 ms 9548 KB Output is correct
5 Correct 20 ms 9560 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 21 ms 9564 KB Output is correct
8 Correct 18 ms 9564 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 20 ms 9572 KB Output is correct
11 Correct 20 ms 9560 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 21 ms 9492 KB Output is correct
14 Correct 19 ms 9564 KB Output is correct
15 Correct 43 ms 9156 KB Output is correct
16 Correct 35 ms 7856 KB Output is correct
17 Correct 43 ms 8028 KB Output is correct
18 Correct 48 ms 9564 KB Output is correct
19 Correct 45 ms 9564 KB Output is correct
20 Correct 55 ms 9564 KB Output is correct
21 Correct 47 ms 9568 KB Output is correct
22 Correct 46 ms 9564 KB Output is correct
23 Correct 47 ms 9564 KB Output is correct
24 Correct 33 ms 9560 KB Output is correct
25 Correct 32 ms 9572 KB Output is correct
26 Correct 30 ms 9576 KB Output is correct
27 Correct 37 ms 9560 KB Output is correct
28 Correct 26 ms 9564 KB Output is correct
29 Correct 26 ms 9564 KB Output is correct
30 Correct 26 ms 8364 KB Output is correct
31 Correct 23 ms 8028 KB Output is correct
32 Correct 25 ms 8024 KB Output is correct
33 Correct 26 ms 9560 KB Output is correct
34 Correct 31 ms 8284 KB Output is correct
35 Correct 22 ms 8280 KB Output is correct
36 Correct 16 ms 8204 KB Output is correct
37 Correct 17 ms 7260 KB Output is correct
38 Correct 19 ms 8028 KB Output is correct
39 Correct 20 ms 7768 KB Output is correct
40 Correct 18 ms 8028 KB Output is correct
41 Correct 21 ms 8280 KB Output is correct
42 Correct 26 ms 9564 KB Output is correct
43 Correct 19 ms 9564 KB Output is correct
44 Correct 20 ms 9564 KB Output is correct
45 Correct 19 ms 9564 KB Output is correct
46 Correct 15 ms 7512 KB Output is correct
47 Correct 11 ms 4188 KB Output is correct
48 Correct 140 ms 52788 KB Output is correct
49 Correct 132 ms 52912 KB Output is correct
50 Correct 81 ms 41296 KB Output is correct
51 Correct 140 ms 52548 KB Output is correct
52 Correct 127 ms 52564 KB Output is correct
53 Correct 44 ms 19032 KB Output is correct
54 Correct 128 ms 52784 KB Output is correct
55 Correct 125 ms 52544 KB Output is correct
56 Correct 29 ms 17756 KB Output is correct
57 Correct 135 ms 52752 KB Output is correct
58 Correct 131 ms 52564 KB Output is correct
59 Correct 332 ms 46416 KB Output is correct
60 Correct 320 ms 44368 KB Output is correct
61 Correct 335 ms 43600 KB Output is correct
62 Correct 430 ms 52784 KB Output is correct
63 Correct 466 ms 52912 KB Output is correct
64 Correct 423 ms 52816 KB Output is correct
65 Correct 410 ms 52808 KB Output is correct
66 Correct 409 ms 52860 KB Output is correct
67 Correct 419 ms 52812 KB Output is correct
68 Correct 264 ms 52816 KB Output is correct
69 Correct 261 ms 52784 KB Output is correct
70 Correct 239 ms 52660 KB Output is correct
71 Correct 221 ms 52732 KB Output is correct
72 Correct 234 ms 52776 KB Output is correct
73 Correct 214 ms 52784 KB Output is correct
74 Correct 149 ms 46016 KB Output is correct
75 Correct 155 ms 43364 KB Output is correct
76 Correct 163 ms 52564 KB Output is correct
77 Correct 133 ms 49240 KB Output is correct
78 Correct 164 ms 52048 KB Output is correct
79 Correct 125 ms 46416 KB Output is correct
80 Correct 117 ms 48208 KB Output is correct
81 Correct 140 ms 41072 KB Output is correct
82 Correct 139 ms 46152 KB Output is correct
83 Correct 116 ms 42324 KB Output is correct
84 Correct 139 ms 45952 KB Output is correct
85 Correct 119 ms 44884 KB Output is correct
86 Correct 128 ms 52872 KB Output is correct
87 Correct 126 ms 52652 KB Output is correct
88 Correct 129 ms 52560 KB Output is correct
89 Correct 127 ms 52564 KB Output is correct
90 Correct 126 ms 51548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 31 ms 7772 KB Output is correct
4 Runtime error 1104 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 41 ms 9548 KB Output is correct
5 Correct 20 ms 9560 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 21 ms 9564 KB Output is correct
8 Correct 18 ms 9564 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 20 ms 9572 KB Output is correct
11 Correct 20 ms 9560 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 21 ms 9492 KB Output is correct
14 Correct 19 ms 9564 KB Output is correct
15 Correct 43 ms 9156 KB Output is correct
16 Correct 35 ms 7856 KB Output is correct
17 Correct 43 ms 8028 KB Output is correct
18 Correct 48 ms 9564 KB Output is correct
19 Correct 45 ms 9564 KB Output is correct
20 Correct 55 ms 9564 KB Output is correct
21 Correct 47 ms 9568 KB Output is correct
22 Correct 46 ms 9564 KB Output is correct
23 Correct 47 ms 9564 KB Output is correct
24 Correct 33 ms 9560 KB Output is correct
25 Correct 32 ms 9572 KB Output is correct
26 Correct 30 ms 9576 KB Output is correct
27 Correct 37 ms 9560 KB Output is correct
28 Correct 26 ms 9564 KB Output is correct
29 Correct 26 ms 9564 KB Output is correct
30 Correct 26 ms 8364 KB Output is correct
31 Correct 23 ms 8028 KB Output is correct
32 Correct 25 ms 8024 KB Output is correct
33 Correct 26 ms 9560 KB Output is correct
34 Correct 31 ms 8284 KB Output is correct
35 Correct 22 ms 8280 KB Output is correct
36 Correct 16 ms 8204 KB Output is correct
37 Correct 17 ms 7260 KB Output is correct
38 Correct 19 ms 8028 KB Output is correct
39 Correct 20 ms 7768 KB Output is correct
40 Correct 18 ms 8028 KB Output is correct
41 Correct 21 ms 8280 KB Output is correct
42 Correct 26 ms 9564 KB Output is correct
43 Correct 19 ms 9564 KB Output is correct
44 Correct 20 ms 9564 KB Output is correct
45 Correct 19 ms 9564 KB Output is correct
46 Correct 15 ms 7512 KB Output is correct
47 Correct 11 ms 4188 KB Output is correct
48 Correct 140 ms 52788 KB Output is correct
49 Correct 132 ms 52912 KB Output is correct
50 Correct 81 ms 41296 KB Output is correct
51 Correct 140 ms 52548 KB Output is correct
52 Correct 127 ms 52564 KB Output is correct
53 Correct 44 ms 19032 KB Output is correct
54 Correct 128 ms 52784 KB Output is correct
55 Correct 125 ms 52544 KB Output is correct
56 Correct 29 ms 17756 KB Output is correct
57 Correct 135 ms 52752 KB Output is correct
58 Correct 131 ms 52564 KB Output is correct
59 Correct 332 ms 46416 KB Output is correct
60 Correct 320 ms 44368 KB Output is correct
61 Correct 335 ms 43600 KB Output is correct
62 Correct 430 ms 52784 KB Output is correct
63 Correct 466 ms 52912 KB Output is correct
64 Correct 423 ms 52816 KB Output is correct
65 Correct 410 ms 52808 KB Output is correct
66 Correct 409 ms 52860 KB Output is correct
67 Correct 419 ms 52812 KB Output is correct
68 Correct 264 ms 52816 KB Output is correct
69 Correct 261 ms 52784 KB Output is correct
70 Correct 239 ms 52660 KB Output is correct
71 Correct 221 ms 52732 KB Output is correct
72 Correct 234 ms 52776 KB Output is correct
73 Correct 214 ms 52784 KB Output is correct
74 Correct 149 ms 46016 KB Output is correct
75 Correct 155 ms 43364 KB Output is correct
76 Correct 163 ms 52564 KB Output is correct
77 Correct 133 ms 49240 KB Output is correct
78 Correct 164 ms 52048 KB Output is correct
79 Correct 125 ms 46416 KB Output is correct
80 Correct 117 ms 48208 KB Output is correct
81 Correct 140 ms 41072 KB Output is correct
82 Correct 139 ms 46152 KB Output is correct
83 Correct 116 ms 42324 KB Output is correct
84 Correct 139 ms 45952 KB Output is correct
85 Correct 119 ms 44884 KB Output is correct
86 Correct 128 ms 52872 KB Output is correct
87 Correct 126 ms 52652 KB Output is correct
88 Correct 129 ms 52560 KB Output is correct
89 Correct 127 ms 52564 KB Output is correct
90 Correct 126 ms 51548 KB Output is correct
91 Correct 31 ms 7772 KB Output is correct
92 Runtime error 1104 ms 1048576 KB Execution killed with signal 9
93 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 41 ms 9548 KB Output is correct
5 Correct 20 ms 9560 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 21 ms 9564 KB Output is correct
8 Correct 18 ms 9564 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 20 ms 9572 KB Output is correct
11 Correct 20 ms 9560 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 21 ms 9492 KB Output is correct
14 Correct 19 ms 9564 KB Output is correct
15 Correct 43 ms 9156 KB Output is correct
16 Correct 35 ms 7856 KB Output is correct
17 Correct 43 ms 8028 KB Output is correct
18 Correct 48 ms 9564 KB Output is correct
19 Correct 45 ms 9564 KB Output is correct
20 Correct 55 ms 9564 KB Output is correct
21 Correct 47 ms 9568 KB Output is correct
22 Correct 46 ms 9564 KB Output is correct
23 Correct 47 ms 9564 KB Output is correct
24 Correct 33 ms 9560 KB Output is correct
25 Correct 32 ms 9572 KB Output is correct
26 Correct 30 ms 9576 KB Output is correct
27 Correct 37 ms 9560 KB Output is correct
28 Correct 26 ms 9564 KB Output is correct
29 Correct 26 ms 9564 KB Output is correct
30 Correct 26 ms 8364 KB Output is correct
31 Correct 23 ms 8028 KB Output is correct
32 Correct 25 ms 8024 KB Output is correct
33 Correct 26 ms 9560 KB Output is correct
34 Correct 31 ms 8284 KB Output is correct
35 Correct 22 ms 8280 KB Output is correct
36 Correct 16 ms 8204 KB Output is correct
37 Correct 17 ms 7260 KB Output is correct
38 Correct 19 ms 8028 KB Output is correct
39 Correct 20 ms 7768 KB Output is correct
40 Correct 18 ms 8028 KB Output is correct
41 Correct 21 ms 8280 KB Output is correct
42 Correct 26 ms 9564 KB Output is correct
43 Correct 19 ms 9564 KB Output is correct
44 Correct 20 ms 9564 KB Output is correct
45 Correct 19 ms 9564 KB Output is correct
46 Correct 15 ms 7512 KB Output is correct
47 Correct 11 ms 4188 KB Output is correct
48 Correct 140 ms 52788 KB Output is correct
49 Correct 132 ms 52912 KB Output is correct
50 Correct 81 ms 41296 KB Output is correct
51 Correct 140 ms 52548 KB Output is correct
52 Correct 127 ms 52564 KB Output is correct
53 Correct 44 ms 19032 KB Output is correct
54 Correct 128 ms 52784 KB Output is correct
55 Correct 125 ms 52544 KB Output is correct
56 Correct 29 ms 17756 KB Output is correct
57 Correct 135 ms 52752 KB Output is correct
58 Correct 131 ms 52564 KB Output is correct
59 Correct 332 ms 46416 KB Output is correct
60 Correct 320 ms 44368 KB Output is correct
61 Correct 335 ms 43600 KB Output is correct
62 Correct 430 ms 52784 KB Output is correct
63 Correct 466 ms 52912 KB Output is correct
64 Correct 423 ms 52816 KB Output is correct
65 Correct 410 ms 52808 KB Output is correct
66 Correct 409 ms 52860 KB Output is correct
67 Correct 419 ms 52812 KB Output is correct
68 Correct 264 ms 52816 KB Output is correct
69 Correct 261 ms 52784 KB Output is correct
70 Correct 239 ms 52660 KB Output is correct
71 Correct 221 ms 52732 KB Output is correct
72 Correct 234 ms 52776 KB Output is correct
73 Correct 214 ms 52784 KB Output is correct
74 Correct 149 ms 46016 KB Output is correct
75 Correct 155 ms 43364 KB Output is correct
76 Correct 163 ms 52564 KB Output is correct
77 Correct 133 ms 49240 KB Output is correct
78 Correct 164 ms 52048 KB Output is correct
79 Correct 125 ms 46416 KB Output is correct
80 Correct 117 ms 48208 KB Output is correct
81 Correct 140 ms 41072 KB Output is correct
82 Correct 139 ms 46152 KB Output is correct
83 Correct 116 ms 42324 KB Output is correct
84 Correct 139 ms 45952 KB Output is correct
85 Correct 119 ms 44884 KB Output is correct
86 Correct 128 ms 52872 KB Output is correct
87 Correct 126 ms 52652 KB Output is correct
88 Correct 129 ms 52560 KB Output is correct
89 Correct 127 ms 52564 KB Output is correct
90 Correct 126 ms 51548 KB Output is correct
91 Correct 31 ms 7772 KB Output is correct
92 Runtime error 1104 ms 1048576 KB Execution killed with signal 9
93 Halted 0 ms 0 KB -