답안 #925817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925817 2024-02-12T09:18:53 Z vjudge1 Nautilus (BOI19_nautilus) C++17
29 / 100
955 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;

const ll mod=1e9+7;
const ll inf=mod;
const int N=5e5+4;

int X[]={0,0,1,-1};
int Y[]={1,-1,0,0};

int n,m,k,used[600][600];
char c[600][600];
string s;
	
int bfs(int x,int y){
	queue<pair<int,pair<int,int>>>q;
	int ok=0;
	q.push({x,{y,0}});
	while(!q.empty()){
		int x=q.front().first,y=q.front().second.first,yy=q.front().second.second;
		q.pop();
		if(yy==s.size()) return 1;
		int l=0,r=4;
		if(s[yy]=='E') r=1;
		if(s[yy]=='W') {
			l=1;
			r=2;
		}
		if(s[yy]=='S') {
			l=2;
			r=3;
		}
		if(s[yy]=='N') {
			l=3;
			r=4;
		}
		//int ok=0;
		for(int i=l; i<r; ++i){
			int tx=x+X[i];
			int ty=y+Y[i];
			if(tx<=n && ty<=m && min(tx,ty)>=1 && c[tx][ty]=='.'){
				q.push({tx,{ty,yy+1}});
		//		++ok;
			}
		}
	}
	return 0;
}

void solve(){
	cin>>n>>m>>k;
	for(int i=1; i<=n; ++i){
		string cc;
		cin>>cc;
		for(int j=1; j<=m; ++j){
			c[i][j]=cc[j-1];
		}
	}
	cin>>s;
	int mx=0;
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=m; ++j){
			if(c[i][j]=='.') mx+=bfs(i,j);
		}
	}
	cout<<mx<<endl;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt=1;
	//	cin>>tt;
	while(tt--) {
		solve();
	}
}

Compilation message

nautilus.cpp: In function 'int bfs(int, int)':
nautilus.cpp:29:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if(yy==s.size()) return 1;
      |      ~~^~~~~~~~~~
nautilus.cpp:24:6: warning: unused variable 'ok' [-Wunused-variable]
   24 |  int ok=0;
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Runtime error 955 ms 262144 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Runtime error 955 ms 262144 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -