Submission #1219941

#TimeUsernameProblemLanguageResultExecution timeMemory
1219941goulthenNautilus (BOI19_nautilus)C++20
100 / 100
180 ms820 KiB
//#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define rep(i, a, b) for (int i = a; i <= b; ++i) #define per(i, b, a) for (int i = b; i >= a; --i) #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define lsb(x) (x)&(-x) void setIO(string name = "") { ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); if (!name.empty()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } ll fexp(ll a, ll b, ll m) { if (b == 0) return 1LL; ll p = a; ll ans = 1; while (b > 0) { if (b % 2 != 0) ans = (ans*p)%m; p = (p*p)%m; b >>= 1; } return ans; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 5e2+10; const int INF = 1e18+5; const int MOD = 1e9+7; char a[MAXN][MAXN]; bitset<510> dp[2][MAXN], mask[MAXN]; int n,m,k; string cm; void solve() { cin >> n >> m >> k; rep(i,1,n) { string s;cin >> s; rep(j,1,m) { a[i][j] = s[j-1]; if (a[i][j] == '.') dp[0][i][j] = 1, mask[i][j] = 1;; } } cin >> cm; rep(l,0,k-1) { rep(i,1,n) { dp[1][i].reset(); } rep(i,1,n) { if (i < n && (cm[l] == 'N' || cm[l] == '?')) dp[1][i] = (dp[1][i] | dp[0][i+1]); if (i > 1 && (cm[l] == 'S' || cm[l] == '?')) dp[1][i] = (dp[1][i] | dp[0][i-1]); if (cm[l] == 'W' || cm[l] == '?') dp[1][i] = (dp[1][i] | (dp[0][i]>>1)); if (cm[l] == 'E' || cm[l] == '?') dp[1][i] = (dp[1][i] | (dp[0][i]<<1)); dp[1][i] = (dp[1][i]&mask[i]); } rep(i,1,n) { dp[0][i] = dp[1][i]; } } int cnt = 0; rep(i,1,n) rep(j,1,m) if (a[i][j] == '.') cnt+=dp[0][i][j]; cout << cnt << '\n'; } int32_t main() { setIO(); int tt = 1; //cin >> tt; while (tt-- > 0) solve(); }

Compilation message (stderr)

nautilus.cpp: In function 'void setIO(std::string)':
nautilus.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...