Submission #257965

# Submission time Handle Problem Language Result Execution time Memory
257965 2020-08-05T06:33:50 Z 송준혁(#5048) Sandwich (JOI16_sandwich) C++17
35 / 100
8000 ms 19568 KB
#include <bits/stdc++.h>
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define mup(a,x) a=min(a,x)
#define Mup(a,x) a=max(a,x)
#define INF 1234567890
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

LL ans;
int N, M;
char C[440][440];
vector<int> adj[320202];
bool P[320202], chk[320202];

int id(int x, int y, int d){return M*(x-1)+(y-1)+d*N*M;}

int dfs(int u){
	if (P[u]) return -1;
	if (chk[u]) return 0;
	int r=1;
	P[u] = chk[u] = true;
	for (int v : adj[u]){
		int t = dfs(v);
		if (t == -1){
			P[u] = false;
			return -1;
		}
		r += t;
	}
	P[u] = false;
	return r;
}

int main(){
	scanf("%d %d", &N, &M);
	for (int i=1; i<=N; i++) scanf("%s", C[i]+1);
	for (int i=1; i<=N; i++) for (int j=1; j<=M; j++){
		if (C[i][j] == 'N'){
			if (C[i][j+1]) adj[id(i,j,0)].pb(id(i,j+1,C[i][j+1]=='Z'));
			if (C[i-1][j]) adj[id(i,j,0)].pb(id(i-1,j,0));

			if (C[i][j-1]) adj[id(i,j,1)].pb(id(i,j-1,C[i][j-1]=='N'));
			if (C[i+1][j]) adj[id(i,j,1)].pb(id(i+1,j,1));
		}
		else{
			if (C[i][j-1]) adj[id(i,j,0)].pb(id(i,j-1,C[i][j-1]=='N'));
			if (C[i-1][j]) adj[id(i,j,0)].pb(id(i-1,j,0));

			if (C[i][j+1]) adj[id(i,j,1)].pb(id(i,j+1,C[i][j+1]=='Z'));
			if (C[i+1][j]) adj[id(i,j,1)].pb(id(i+1,j,1));
		}
	}
	for (int i=1; i<=N; i++){
		for (int j=1; j<=M; j++){
			memset(chk, 0, sizeof chk);
			int x = dfs(id(i,j,0));
			memset(chk, 0, sizeof chk);
			int y = dfs(id(i,j,1));
			if (x<0 && y<0) printf("-1 "); 
			else if (x<0 || y<0) printf("%d ", 2*max(x,y));
			else printf("%d ", 2*min(x,y));
		}
		printf("\n");
	}
	return 0;
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
sandwich.cpp:40:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=N; i++) scanf("%s", C[i]+1);
                           ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8192 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 5 ms 8192 KB Output is correct
4 Correct 5 ms 8192 KB Output is correct
5 Correct 7 ms 8192 KB Output is correct
6 Correct 64 ms 8320 KB Output is correct
7 Correct 120 ms 8320 KB Output is correct
8 Correct 127 ms 8320 KB Output is correct
9 Correct 79 ms 8320 KB Output is correct
10 Correct 134 ms 8320 KB Output is correct
11 Correct 197 ms 8400 KB Output is correct
12 Correct 79 ms 8312 KB Output is correct
13 Correct 219 ms 8320 KB Output is correct
14 Correct 206 ms 8320 KB Output is correct
15 Correct 84 ms 8320 KB Output is correct
16 Correct 114 ms 8320 KB Output is correct
17 Correct 118 ms 8320 KB Output is correct
18 Correct 114 ms 8320 KB Output is correct
19 Correct 112 ms 8320 KB Output is correct
20 Correct 84 ms 8320 KB Output is correct
21 Correct 86 ms 8320 KB Output is correct
22 Correct 86 ms 8388 KB Output is correct
23 Correct 87 ms 8320 KB Output is correct
24 Correct 213 ms 8440 KB Output is correct
25 Correct 216 ms 8524 KB Output is correct
26 Correct 235 ms 8440 KB Output is correct
27 Correct 124 ms 8568 KB Output is correct
28 Correct 191 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8192 KB Output is correct
2 Correct 6 ms 8192 KB Output is correct
3 Correct 5 ms 8192 KB Output is correct
4 Correct 5 ms 8192 KB Output is correct
5 Correct 7 ms 8192 KB Output is correct
6 Correct 64 ms 8320 KB Output is correct
7 Correct 120 ms 8320 KB Output is correct
8 Correct 127 ms 8320 KB Output is correct
9 Correct 79 ms 8320 KB Output is correct
10 Correct 134 ms 8320 KB Output is correct
11 Correct 197 ms 8400 KB Output is correct
12 Correct 79 ms 8312 KB Output is correct
13 Correct 219 ms 8320 KB Output is correct
14 Correct 206 ms 8320 KB Output is correct
15 Correct 84 ms 8320 KB Output is correct
16 Correct 114 ms 8320 KB Output is correct
17 Correct 118 ms 8320 KB Output is correct
18 Correct 114 ms 8320 KB Output is correct
19 Correct 112 ms 8320 KB Output is correct
20 Correct 84 ms 8320 KB Output is correct
21 Correct 86 ms 8320 KB Output is correct
22 Correct 86 ms 8388 KB Output is correct
23 Correct 87 ms 8320 KB Output is correct
24 Correct 213 ms 8440 KB Output is correct
25 Correct 216 ms 8524 KB Output is correct
26 Correct 235 ms 8440 KB Output is correct
27 Correct 124 ms 8568 KB Output is correct
28 Correct 191 ms 8576 KB Output is correct
29 Correct 13 ms 8192 KB Output is correct
30 Correct 13 ms 8320 KB Output is correct
31 Correct 7535 ms 19504 KB Output is correct
32 Execution timed out 8069 ms 19568 KB Time limit exceeded
33 Halted 0 ms 0 KB -