Submission #211807

#TimeUsernameProblemLanguageResultExecution timeMemory
211807origami100Nautilus (BOI19_nautilus)C++11
0 / 100
6 ms384 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int r, c, m; cin >> r >> c >> m; int grid[r][c], dp[r][c]; for(int i = 0; i < r; i++){ string s; cin >> s; for(int j = 0; j < c; j++){ if(s[j] == '.'){ grid[i][j] = 1; dp[i][j] = 1; }else{ grid[i][j] = 0; dp[i][j] = 0; } } } for(int i = 0; i < m; i++){ char ins; cin >> ins; switch(ins){ case 'N': for(int j = 0; j < r - 1; j++){ for(int k = 0; k < c; k++){ dp[j][k] = (grid[j][k] == 1 && dp[j + 1][k] == 1)?1:0; } } for(int k = 0; k < c; k++) dp[r - 1][k] = 0; break; case 'S': for(int j = r - 1; j > 0; j--){ for(int k = 0; k < c; k++){ dp[j][k] = (grid[j][k] == 1 && dp[j - 1][k] == 1)?1:0; } } for(int k = 0; k < c; k++) dp[0][k] = 0; break; case 'W': for(int j = 0; j < r; j++){ for(int k = 0; k < c - 1; k++){ dp[j][j] = (grid[j][k] == 1 && dp[j][k + 1] == 1)?1:0; } } for(int k = 0; k < r; k++) dp[k][c - 1] = 0; break; case 'E': for(int j = 0; j < r; j++){ for(int k = c - 1; k > 0; k--){ dp[j][k] = (grid[j][k] == 1 && dp[j][k - 1] == 1)?1:0; } } for(int k = 0; k < r; k++) dp[k][0] = 0; break; case '?': int prev[r][c]; for(int j = 0; j < r; j++){ for(int k = 0; k < c; k++){ prev[j][k] = dp[j][k]; } } for(int j = 0; j < r; j++){ for(int k = 0; k < c; k++){ if(grid[j][k] == 1){ if(j == 0){ if(k == 0) dp[j][k] = (prev[j + 1][k] == 1 || prev[j][k + 1] == 1)?1:0; else if(k == c - 1) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1)?1:0; else dp[j][k] = (prev[j + 1][k] == 1 || prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0; }else if(j == r - 1){ if(k == 0) dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k + 1] == 1)?1:0; else if(k == c - 1) dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k - 1] == 1)?1:0; else dp[j][k] = (prev[j - 1][k] == 1 || prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0; }else{ if(k == 0) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k + 1] == 1)?1:0; else if(k == c - 1) dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k - 1] == 1)?1:0; else dp[j][k] = (prev[j + 1][k] == 1 || prev[j - 1][k] == 1|| prev[j][k + 1] == 1 || prev[j][k - 1] == 1)?1:0; } } } } break; } /*for(int j = 0; j < r; j++){ for(int k = 0; k < c; k++){ cout << dp[j][k]; } cout << '\n'; } cout << '\n';*/ } int cnt = 0; for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ if(dp[i][j] == 1) cnt++; } } cout << cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...