Submission #1265818

#TimeUsernameProblemLanguageResultExecution timeMemory
1265818minggaNautilus (BOI19_nautilus)C++20
66 / 100
1095 ms328 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; int n, m, k, idd[150]; pair<int, int> d[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; bitset<505> f[2][505], a[505]; signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n >> m >> k; idd['N'] = 1; idd['S'] = 0; idd['E'] = 3; idd['W'] = 2; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { char c; cin >> c; f[0][i][j] = (c == '.'); a[i][j] = f[0][i][j]; } } string s; cin >> s; for(int t = 1; t <= k; t++) { char c = s[t - 1]; int id = t & 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { f[id][i][j] = 0; if(c == '?') { if(a[i][j] == 0) continue; for(int z = 0; z < 4; z++) { int nx = i + d[z].fi, ny = j + d[z].se; if(nx < 1 or ny < 1 or nx > n or ny > m) continue; f[id][i][j] = f[id ^ 1][nx][ny]; if(f[id][i][j]) break; } } else { auto [nx, ny] = d[idd[c]]; int x = i + nx, y = j + ny; if(x < 1 or y < 1 or x > n or y > m) continue; f[id][i][j] = (f[id ^ 1][x][y] && a[i][j]); } } } } int ans = 0; for(int i = 1; i <= n; i++) { ans += f[k & 1][i].count(); } cout << ans << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:25:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:26:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...