답안 #260319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260319 2020-08-10T05:13:17 Z arnold518 Nautilus (BOI19_nautilus) C++14
66 / 100
1000 ms 161912 KB
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 500;
const int MAXM = 5000;

int R, C, M;
char S[MAXN+10][MAXN+10];
char A[MAXM+10];
ll B[MAXN+10][MAXN+10];
ll D[MAXN+10][MAXN/64+10][MAXM+10];

int main()
{
	scanf("%d%d%d", &R, &C, &M);
	for(int i=1; i<=R; i++) scanf("%s", S[i]+1);
	scanf("%s", A+1);

	for(int i=1; i<=R; i++) for(int j=1; j<=C; j++) if(S[i][j]=='.') B[i][j/64]|=(1ll<<(j%64));
	for(int i=1; i<=R; i++) for(int j=0; j<=C/64; j++) D[i][j][0]=B[i][j];

	for(int p=1; p<=M; p++)
	{
		if(A[p]=='N')
		{
			for(int i=1; i<R; i++) for(int j=0; j<=C/64; j++)
			{
				D[i][j][p]=D[i+1][j][p-1];
				D[i][j][p]&=B[i][j];
			}
		}
		if(A[p]=='S')
		{
			for(int i=2; i<=R; i++) for(int j=0; j<=C/64; j++)
			{
				D[i][j][p]=D[i-1][j][p-1];
				D[i][j][p]&=B[i][j];
			}	
		}
		if(A[p]=='E')
		{
			for(int i=1; i<=R; i++)
			{
				for(int j=C/64; j>=0; j--)
				{
					D[i][j][p]=D[i][j][p-1]<<1;
					D[i][j][p]&=((1ll<<64)-1);
					if(j!=0 && (D[i][j-1][p-1]&(1ll<<63))) D[i][j][p]|=1;
					D[i][j][p]&=B[i][j];
				}
			}
		}
		if(A[p]=='W')
		{
			for(int i=1; i<=R; i++)
			{
				for(int j=0; j<=C/64; j++)
				{
					D[i][j][p]=D[i][j][p-1]>>1;
					if(j!=C/64 && (D[i][j+1][p-1]&1)) D[i][j][p]|=(1ll<<63);
					D[i][j][p]&=B[i][j];
				}
			}
		}
		if(A[p]=='?')
		{
			for(int i=1; i<=R; i++) for(int j=0; j<=C/64; j++)
			{
				if(i!=R) D[i][j][p]|=D[i+1][j][p-1];
				if(i!=1) D[i][j][p]|=D[i-1][j][p-1];
			}
			for(int i=1; i<=R; i++)
			{
				for(int j=C/64; j>=0; j--)
				{
					ll t;
					t=D[i][j][p-1]<<1;
					t&=((1ll<<64)-1);
					if(j!=0 && (D[i][j-1][p-1]&(1ll<<63))) t|=1;
					D[i][j][p]|=t;
				}
			}
			for(int i=1; i<=R; i++)
			{
				for(int j=0; j<=C/64; j++)
				{
					ll t;
					t=D[i][j][p-1]>>1;
					if(j!=C/64 && (D[i][j+1][p-1]&1)) t|=(1ll<<63);
					t&=B[i][j];
					D[i][j][p]|=t;
				}
			}
			for(int i=1; i<=R; i++) for(int j=0; j<=C/64; j++) D[i][j][p]&=B[i][j];
		}
	}
	int ans=0;
	for(int i=1; i<=R; i++) for(int j=0; j<=C/64; j++) ans+=__builtin_popcountll(D[i][j][M]);
	printf("%d\n", ans);
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:51:25: warning: left shift count >= width of type [-Wshift-count-overflow]
      D[i][j][p]&=((1ll<<64)-1);
                         ^~
nautilus.cpp:82:16: warning: left shift count >= width of type [-Wshift-count-overflow]
      t&=((1ll<<64)-1);
                ^~
nautilus.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &R, &C, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=R; i++) scanf("%s", S[i]+1);
                          ~~~~~^~~~~~~~~~~~~~
nautilus.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", A+1);
  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1824 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1824 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1536 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 1 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1536 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 1 ms 1920 KB Output is correct
21 Correct 1 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1824 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1536 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 1 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1536 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 1 ms 1920 KB Output is correct
21 Correct 1 ms 1536 KB Output is correct
22 Correct 725 ms 161840 KB Output is correct
23 Correct 736 ms 161784 KB Output is correct
24 Correct 714 ms 161712 KB Output is correct
25 Correct 714 ms 161772 KB Output is correct
26 Correct 703 ms 160120 KB Output is correct
27 Execution timed out 1092 ms 161912 KB Time limit exceeded
28 Halted 0 ms 0 KB -