Submission #258024

# Submission time Handle Problem Language Result Execution time Memory
258024 2020-08-05T08:27:04 Z 임성재(#5053) Sandwich (JOI16_sandwich) C++17
35 / 100
8000 ms 25212 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[330010];
bool chk[330010];
bool chk2[330010];

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, 330000);
			memset(chk2, 0, 330000);

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

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

			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 5 ms 8704 KB Output is correct
2 Correct 7 ms 8960 KB Output is correct
3 Correct 9 ms 8704 KB Output is correct
4 Correct 6 ms 8704 KB Output is correct
5 Correct 10 ms 8704 KB Output is correct
6 Correct 597 ms 8960 KB Output is correct
7 Correct 173 ms 8952 KB Output is correct
8 Correct 182 ms 8960 KB Output is correct
9 Correct 123 ms 8832 KB Output is correct
10 Correct 193 ms 9080 KB Output is correct
11 Correct 249 ms 8960 KB Output is correct
12 Correct 109 ms 8892 KB Output is correct
13 Correct 254 ms 8960 KB Output is correct
14 Correct 244 ms 9080 KB Output is correct
15 Correct 136 ms 8952 KB Output is correct
16 Correct 158 ms 8952 KB Output is correct
17 Correct 164 ms 9080 KB Output is correct
18 Correct 163 ms 8956 KB Output is correct
19 Correct 163 ms 8952 KB Output is correct
20 Correct 146 ms 8952 KB Output is correct
21 Correct 152 ms 8960 KB Output is correct
22 Correct 153 ms 8952 KB Output is correct
23 Correct 153 ms 8960 KB Output is correct
24 Correct 257 ms 8968 KB Output is correct
25 Correct 255 ms 9084 KB Output is correct
26 Correct 234 ms 8960 KB Output is correct
27 Correct 155 ms 8968 KB Output is correct
28 Correct 205 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8704 KB Output is correct
2 Correct 7 ms 8960 KB Output is correct
3 Correct 9 ms 8704 KB Output is correct
4 Correct 6 ms 8704 KB Output is correct
5 Correct 10 ms 8704 KB Output is correct
6 Correct 597 ms 8960 KB Output is correct
7 Correct 173 ms 8952 KB Output is correct
8 Correct 182 ms 8960 KB Output is correct
9 Correct 123 ms 8832 KB Output is correct
10 Correct 193 ms 9080 KB Output is correct
11 Correct 249 ms 8960 KB Output is correct
12 Correct 109 ms 8892 KB Output is correct
13 Correct 254 ms 8960 KB Output is correct
14 Correct 244 ms 9080 KB Output is correct
15 Correct 136 ms 8952 KB Output is correct
16 Correct 158 ms 8952 KB Output is correct
17 Correct 164 ms 9080 KB Output is correct
18 Correct 163 ms 8956 KB Output is correct
19 Correct 163 ms 8952 KB Output is correct
20 Correct 146 ms 8952 KB Output is correct
21 Correct 152 ms 8960 KB Output is correct
22 Correct 153 ms 8952 KB Output is correct
23 Correct 153 ms 8960 KB Output is correct
24 Correct 257 ms 8968 KB Output is correct
25 Correct 255 ms 9084 KB Output is correct
26 Correct 234 ms 8960 KB Output is correct
27 Correct 155 ms 8968 KB Output is correct
28 Correct 205 ms 9080 KB Output is correct
29 Correct 21 ms 8832 KB Output is correct
30 Correct 23 ms 8704 KB Output is correct
31 Execution timed out 8064 ms 25212 KB Time limit exceeded
32 Halted 0 ms 0 KB -