Submission #258021

# Submission time Handle Problem Language Result Execution time Memory
258021 2020-08-05T08:25:55 Z 임성재(#5053) Sandwich (JOI16_sandwich) C++17
35 / 100
556 ms 19704 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, m;
string s[444];
vector<int> g[170010];
bool chk[170010];
bool chk2[170010];

int dfs(int x) {
	chk[x] = true;
	chk2[x] = true;

	int ret = 1;

	for(auto i : g[x]) {
		if(chk[i]) return inf;
		if(chk2[i]) continue;

		ret += dfs(i);
	}

	chk[x] = false;

	return min(ret, inf);
}

int main() {
	fast;

	cin >> n >> m;

	for(int i=0; i<n; i++) {
		cin >> s[i];
	}

	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			if(i < n-1) g[2 * m * i + 2 * j + 1].eb(2 * m * (i+1) + 2 * j + 1);
			if(i > 0) g[2 * m * i + 2 * j].eb(2 * m * (i-1) + 2 * j);

			if(j == m-1) continue;

			if(s[i][j] == 'N' && s[i][j+1] == 'N') 
				g[2 * m * i + 2 * j].eb(2 * m * i + 2 * (j+1)), g[2 * m * i + 2 * (j+1) + 1].eb(2 * m * i + 2 * j + 1);

			if(s[i][j] == 'N' && s[i][j+1] == 'Z') 
				g[2 * m * i + 2 * j].eb(2 * m * i + 2 * (j+1) + 1),  g[2 * m * i + 2 * (j+1)].eb(2 * m * i + 2 * j + 1);

			if(s[i][j] == 'Z' && s[i][j+1] == 'N') 
				g[2 * m * i + 2 * j + 1].eb(2 * m * i + 2 * (j+1)), g[2 * m * i + 2 * (j+1) + 1].eb(2 * m * i + 2 * j);

			if(s[i][j] == 'Z' && s[i][j+1] == 'Z') 
				g[2 * m * i + 2 * j + 1].eb(2 * m * i + 2 * (j+1) + 1),  g[2 * m * i + 2 * (j+1)].eb(2 * m * i + 2 * j);
		}
	}

	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			memset(chk, 0, 170000);
			memset(chk2, 0, 170000);

			int x = dfs(2 * m * i + 2 * j);

			memset(chk, 0, 170000);
			memset(chk2, 0, 170000);

			int y = dfs(2 * m * i + 2 * j + 1);

			if(min(x, y) == inf) cout << "-1 ";
			else cout << min(x, y) * 2 << " ";
		}

		cout << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4608 KB Output is correct
2 Correct 4 ms 4608 KB Output is correct
3 Correct 5 ms 4736 KB Output is correct
4 Correct 4 ms 4608 KB Output is correct
5 Correct 6 ms 4736 KB Output is correct
6 Correct 556 ms 4864 KB Output is correct
7 Correct 139 ms 4864 KB Output is correct
8 Correct 133 ms 4864 KB Output is correct
9 Correct 79 ms 4736 KB Output is correct
10 Correct 140 ms 4984 KB Output is correct
11 Correct 194 ms 4864 KB Output is correct
12 Correct 88 ms 4856 KB Output is correct
13 Correct 202 ms 4864 KB Output is correct
14 Correct 189 ms 4864 KB Output is correct
15 Correct 89 ms 4864 KB Output is correct
16 Correct 126 ms 4864 KB Output is correct
17 Correct 115 ms 4864 KB Output is correct
18 Correct 115 ms 4864 KB Output is correct
19 Correct 118 ms 4864 KB Output is correct
20 Correct 105 ms 4864 KB Output is correct
21 Correct 105 ms 4896 KB Output is correct
22 Correct 101 ms 4864 KB Output is correct
23 Correct 100 ms 4864 KB Output is correct
24 Correct 212 ms 4892 KB Output is correct
25 Correct 189 ms 4864 KB Output is correct
26 Correct 191 ms 4992 KB Output is correct
27 Correct 104 ms 4864 KB Output is correct
28 Correct 169 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4608 KB Output is correct
2 Correct 4 ms 4608 KB Output is correct
3 Correct 5 ms 4736 KB Output is correct
4 Correct 4 ms 4608 KB Output is correct
5 Correct 6 ms 4736 KB Output is correct
6 Correct 556 ms 4864 KB Output is correct
7 Correct 139 ms 4864 KB Output is correct
8 Correct 133 ms 4864 KB Output is correct
9 Correct 79 ms 4736 KB Output is correct
10 Correct 140 ms 4984 KB Output is correct
11 Correct 194 ms 4864 KB Output is correct
12 Correct 88 ms 4856 KB Output is correct
13 Correct 202 ms 4864 KB Output is correct
14 Correct 189 ms 4864 KB Output is correct
15 Correct 89 ms 4864 KB Output is correct
16 Correct 126 ms 4864 KB Output is correct
17 Correct 115 ms 4864 KB Output is correct
18 Correct 115 ms 4864 KB Output is correct
19 Correct 118 ms 4864 KB Output is correct
20 Correct 105 ms 4864 KB Output is correct
21 Correct 105 ms 4896 KB Output is correct
22 Correct 101 ms 4864 KB Output is correct
23 Correct 100 ms 4864 KB Output is correct
24 Correct 212 ms 4892 KB Output is correct
25 Correct 189 ms 4864 KB Output is correct
26 Correct 191 ms 4992 KB Output is correct
27 Correct 104 ms 4864 KB Output is correct
28 Correct 169 ms 4864 KB Output is correct
29 Correct 12 ms 4736 KB Output is correct
30 Correct 12 ms 4736 KB Output is correct
31 Runtime error 34 ms 19704 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -