제출 #752584

#제출 시각아이디문제언어결과실행 시간메모리
752584penguin133Nautilus (BOI19_nautilus)C++17
66 / 100
1076 ms4960 KiB
    #include <bits/stdc++.h>
    using namespace std;
     
    #define int long long
    #define pi pair<int, int>
    #define pii pair<int, pi>
    #define fi first
    #define se second
    #ifdef _WIN32
    #define getchar_unlocked _getchar_nolock
    #endif
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
     
    int r, c, m;
    bitset <501> ok[501];
    char G[501][501];
    string s;
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
     
    void solve(){
    	cin >> r >> c >> m;
    	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++)cin >> G[i][j];
    	queue <pi> q;
    	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++){
    		if(G[i][j] == '.'){
    			q.push({i, j});
    		}
    	}
    	cin >> s;
    	for(int a = 0; a < m; a++){
    		while(!q.empty()){
    			int x = q.front().fi, y = q.front().se;
    			q.pop();
    			if(s[a] != '?'){
    				if(s[a] == 'W'){
    					if(y > 1 && G[x][y-1] != '#')ok[x][y - 1] = 1;
    				}
    				if(s[a] == 'E'){
    					if(y < c && G[x][y+1] != '#')ok[x][y + 1] = 1;
    				}
    				if(s[a] == 'S'){
    					if(x < r && G[x+1][y] != '#')ok[x + 1][y] = 1;
    				}
    				if(s[a] == 'N'){
    					if(x > 1 && G[x-1][y] != '#')ok[x-1][y] = 1;
    				}
    				continue;
    			}
    			for(int i = 0; i < 4; i++){
    				int x1 = x + dx[i], y1 = y + dy[i];
    				if(x1 < 1 || x1 > r || y1 < 1 || y1 > c || G[x1][y1] == '#')continue;
    				ok[x1][y1] = 1;
    			}
    		}
    		for(int i = 1; i <= r; i++)for(int j = 1; j <= c; j++){
    			if(ok[i][j])q.push({i, j});
    			if(a != m - 1)ok[i][j] = 0;
    		}
    	}
    	
    	int ans = 0;
    	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++)ans += ok[i][j];
    	cout << ans;
    }
     
    main(){
    	ios::sync_with_stdio(0);cin.tie(0);
    	int tc = 1;
    	//cin >> tc;
    	for(int tc1=1;tc1<=tc;tc1++){
    		// cout << "Case #" << tc1 << ": ";
    		solve();
    	}
    }

컴파일 시 표준 에러 (stderr) 메시지

nautilus.cpp:66:5: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 |     main(){
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...