Submission #623830

# Submission time Handle Problem Language Result Execution time Memory
623830 2022-08-06T15:20:16 Z Lobo Mars (APIO22_mars) C++17
29 / 100
127 ms 2836 KB
#include "mars.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second


std::string process(std::vector <std::vector<std::string>> a, int i, int j, int k, int n)
{

	vector<pair<int,int>> d = {{0,1},{0,-1},{1,0},{-1,0}};
	// cout << " " << i << " " << j << " " << k << " " << n << endl;
	//i,j -> (i/2)*(n+1)+j/2
	string ans(100,'0');
	if(n == 1) {
		int grid[2*n+1][2*n+1];
		for(int i1 = 0; i1 < 2*n+1; i1++) {
			for(int j1 = 0; j1 < 2*n+1; j1++) {
				grid[i1][j1] = a[i1][j1][0]-'0';
				// cout << grid[i1][j1];
			}
		}
		int cnt = 0;
		for(int i1 = 0; i1 < 2*n+1; i1++) {
			for(int j1 = 0; j1 < 2*n+1; j1++) {
				if(grid[i1][j1]) {
					cnt++;
					queue<pair<int,int>> q;
					q.push(mp(i1,j1));
					grid[i1][j1] = 0;
					while(q.size()) {
						int i2 = q.front().fr;
						int j2 = q.front().sc;
						q.pop();
						for(auto x : d) {
							int i3 = i2+x.fr;
							int j3 = j2+x.sc;
							if(i3 < 0 || j3 < 0 || i3 > 2*n || j3 > 2*n || grid[i3][j3] == 0) continue;
							grid[i3][j3] = 0;
							q.push(mp(i3,j3));
						}
					}
				}
			}
		}
		ans = string(100,'0');
		for(int x = 0; x < 25; x++) {
			if((1<<x)&cnt) ans[x] = '1';
		}
		// cout << ans << endl;
	}
	else if(k == 0) {
		for(int i1 = i; i1 <= i+2; i1+=2) {
			for(int j1 = j; j1 <= j+2; j1+=2) {
				ans[(i1/2)*(n+1)+j1/2] = a[i1-i][j1-j][0];
			}
		}
	}
	else {
		for(int i1 = 0; i1 < 100; i1++) {
			ans[i1] = max(ans[i1],a[0][0][i1]);
			ans[i1] = max(ans[i1],a[2][0][i1]);
			ans[i1] = max(ans[i1],a[0][2][i1]);
			ans[i1] = max(ans[i1],a[2][2][i1]);
		}
		if(k == n-1) {
			a[0][0] = ans;
			int grid[2*n+1][2*n+1];
			// cout << " " << a[0][0] << endl;
			// cout << " " << a[0][1] << endl;
			// cout << " " << a[1][0] << endl;
			// cout << " " << a[1][1] << endl;
			for(int i1 = 0; i1 < 2*n+1; i1++) {
				for(int j1 = 0; j1 < 2*n+1; j1++) {
					grid[i1][j1] = a[i1%2][j1%2][(i1/2)*(n+1)+j1/2]-'0';
					if(i1%2 == 0 && j1%2 == 1) {
						grid[i1][j1] = max(grid[i1][j1],a[2][1][(i1/2)*(n+1)+j1/2]-'0');
					}
					if(i1%2 == 1 && j1%2 == 0) {
						grid[i1][j1] = max(grid[i1][j1],a[1][2][(i1/2)*(n+1)+j1/2]-'0');
					}
					// cout << grid[i1][j1];
				}
			}
			int cnt = 0;
			for(int i1 = 0; i1 < 2*n+1; i1++) {
				for(int j1 = 0; j1 < 2*n+1; j1++) {
					if(grid[i1][j1]) {
						// cout << i1 << " " << j1 << endl;
						cnt++;
						queue<pair<int,int>> q;
						q.push(mp(i1,j1));
						grid[i1][j1] = 0;
						while(q.size()) {
							int i2 = q.front().fr;
							int j2 = q.front().sc;
							q.pop();
							// cout << " " << i2 << " " << j2 << endl;
							for(auto x : d) {
								int i3 = i2+x.fr;
								int j3 = j2+x.sc;
								if(i3 < 0 || j3 < 0 || i3 > 2*n || j3 > 2*n || grid[i3][j3] == 0) continue;
								grid[i3][j3] = 0;
								// cout << "   " << i3 << " " << j3 << endl;
								q.push(mp(i3,j3));
							}
						}
					}
				}
			}
			ans = string(100,'0');
			for(int x = 0; x < 25; x++) {
				if((1<<x)&cnt) ans[x] = '1';
			}
			// cout << ans << endl;
		}
	}
	// cout << i << " " << j << " " << k << " " << ans << endl;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1960 KB Output is correct
2 Correct 8 ms 2036 KB Output is correct
3 Correct 8 ms 1916 KB Output is correct
4 Correct 8 ms 1888 KB Output is correct
5 Correct 8 ms 2124 KB Output is correct
6 Correct 6 ms 2220 KB Output is correct
7 Correct 9 ms 2056 KB Output is correct
8 Correct 16 ms 2144 KB Output is correct
9 Correct 16 ms 1952 KB Output is correct
10 Correct 16 ms 2036 KB Output is correct
11 Correct 16 ms 2144 KB Output is correct
12 Correct 16 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 30 ms 2404 KB Output is correct
15 Correct 40 ms 2488 KB Output is correct
16 Correct 40 ms 2516 KB Output is correct
17 Correct 41 ms 2512 KB Output is correct
18 Correct 41 ms 2620 KB Output is correct
19 Correct 40 ms 2560 KB Output is correct
20 Correct 41 ms 2644 KB Output is correct
21 Correct 63 ms 2616 KB Output is correct
22 Correct 88 ms 2752 KB Output is correct
23 Correct 90 ms 2760 KB Output is correct
24 Correct 92 ms 2652 KB Output is correct
25 Correct 90 ms 2596 KB Output is correct
26 Correct 88 ms 2648 KB Output is correct
27 Correct 89 ms 2836 KB Output is correct
28 Correct 86 ms 2676 KB Output is correct
29 Correct 127 ms 2744 KB Output is correct
30 Runtime error 5 ms 456 KB Execution killed with signal 6
31 Halted 0 ms 0 KB -