Submission #258003

# Submission time Handle Problem Language Result Execution time Memory
258003 2020-08-05T07:50:18 Z 임성재(#5053) Sandwich (JOI16_sandwich) C++17
35 / 100
461 ms 1920 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[10010];
bool chk[10010];
bool chk2[10010];

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

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

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

			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 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 461 ms 1144 KB Output is correct
7 Correct 74 ms 768 KB Output is correct
8 Correct 73 ms 816 KB Output is correct
9 Correct 39 ms 768 KB Output is correct
10 Correct 88 ms 824 KB Output is correct
11 Correct 136 ms 768 KB Output is correct
12 Correct 49 ms 760 KB Output is correct
13 Correct 141 ms 768 KB Output is correct
14 Correct 133 ms 768 KB Output is correct
15 Correct 37 ms 768 KB Output is correct
16 Correct 61 ms 888 KB Output is correct
17 Correct 61 ms 768 KB Output is correct
18 Correct 63 ms 768 KB Output is correct
19 Correct 75 ms 768 KB Output is correct
20 Correct 53 ms 888 KB Output is correct
21 Correct 51 ms 768 KB Output is correct
22 Correct 50 ms 768 KB Output is correct
23 Correct 52 ms 768 KB Output is correct
24 Correct 140 ms 956 KB Output is correct
25 Correct 136 ms 768 KB Output is correct
26 Correct 129 ms 768 KB Output is correct
27 Correct 57 ms 768 KB Output is correct
28 Correct 107 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 461 ms 1144 KB Output is correct
7 Correct 74 ms 768 KB Output is correct
8 Correct 73 ms 816 KB Output is correct
9 Correct 39 ms 768 KB Output is correct
10 Correct 88 ms 824 KB Output is correct
11 Correct 136 ms 768 KB Output is correct
12 Correct 49 ms 760 KB Output is correct
13 Correct 141 ms 768 KB Output is correct
14 Correct 133 ms 768 KB Output is correct
15 Correct 37 ms 768 KB Output is correct
16 Correct 61 ms 888 KB Output is correct
17 Correct 61 ms 768 KB Output is correct
18 Correct 63 ms 768 KB Output is correct
19 Correct 75 ms 768 KB Output is correct
20 Correct 53 ms 888 KB Output is correct
21 Correct 51 ms 768 KB Output is correct
22 Correct 50 ms 768 KB Output is correct
23 Correct 52 ms 768 KB Output is correct
24 Correct 140 ms 956 KB Output is correct
25 Correct 136 ms 768 KB Output is correct
26 Correct 129 ms 768 KB Output is correct
27 Correct 57 ms 768 KB Output is correct
28 Correct 107 ms 768 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Runtime error 3 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -