Submission #348622

#TimeUsernameProblemLanguageResultExecution timeMemory
348622Nima_NaderiNautilus (BOI19_nautilus)C++14
100 / 100
233 ms876 KiB
//In The Name of Allah #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair < int , int > pii; typedef pair < ll , ll > pll; #define X first #define Y second #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x.size()) const int N = 500 + 10; const int M = 5000 + 10; const ll mod = 1e9 + 7; const ll inf = 1e18 + 10; bitset < N > dp[2][N], row[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, len; char c; cin >> n >> m >> len; for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) cin >> c, dp[0][i][j] = row[i][j] = (c == '.'); string s; cin >> s; s = '.' + s; for (int t = 1; t <= len; t ++){ for (int i = 1; i <= n; i ++){ if (s[t] == 'N') dp[t & 1][i] = dp[(t & 1) ^ 1][i + 1] & row[i]; if (s[t] == 'S') dp[t & 1][i] = dp[(t & 1) ^ 1][i - 1] & row[i]; if (s[t] == 'W') dp[t & 1][i] = (dp[(t & 1) ^ 1][i] >> 1) & row[i]; if (s[t] == 'E') dp[t & 1][i] = (dp[(t & 1) ^ 1][i] << 1) & row[i]; if (s[t] == '?') dp[t & 1][i] = (dp[(t & 1) ^ 1][i + 1] | dp[(t & 1) ^ 1][i - 1] | (dp[(t & 1) ^ 1][i] << 1) | (dp[(t & 1) ^ 1][i] >> 1)) & row[i]; } } int ans = 0; for (int i = 1; i <= n; i ++) ans += dp[len & 1][i].count(); cout << ans; return 0; } //codam paride az cms
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...