Submission #211811

#TimeUsernameProblemLanguageResultExecution timeMemory
211811origami100Nautilus (BOI19_nautilus)C++11
66 / 100
1095 ms3200 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); 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; } //cout << dp[i][j]; } //cout << '\n'; } //cout << '\n'; 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][k] = (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][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(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...