제출 #1279345

#제출 시각아이디문제언어결과실행 시간메모리
1279345shidou26Nautilus (BOI19_nautilus)C++20
66 / 100
26 ms1340 KiB
#include <bits/stdc++.h> using namespace std; #ifdef KURUMI #include "algo/debug.h" #endif #define endl '\n' #define fi first #define se second #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() #define filter(v) v.resize(unique(all(v)) - v.begin()) #define dbg(x) "[" #x << " = " << x << "]" mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T1, typename T2> T2 rand(T1 l, T2 r) { return uniform_int_distribution<T2>(l, r)(rng); } template<typename T1, typename T2> T2 wrand(T1 l, T2 r, int seed) { if(seed == 0) return rand(l, r); else return (seed > 0 ? max(rand(l, r), wrand(l, r, seed - 1)) : min(rand(l, r), wrand(l, r, seed + 1))); } template<typename T> bool maximize(T &a, T b) { if(a < b) { a = b; return true; }else return false; } template<typename T> bool minimize(T &a, T b) { if(a > b) { a = b; return true; }else return false; } typedef long long ll; typedef long double ldb; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tp3; const int N = 5e2 + 3; const char BLOCKED = '#'; int n, m, k; char d[N]; char a[N][N]; void input() { cin >> n >> m >> k; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; } } for(int i = 1; i <= k; i++) { cin >> d[i]; } } namespace subtask_2 { bool approve() { return max({n, m, k}) <= 1e2; } const int N = 1e2 + 3; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; void execute() { map<char, int> direction; direction['S'] = 0; direction['E'] = 1; direction['N'] = 2; direction['W'] = 3; vector<vector<vector<bool>>> vis(k + 1, vector<vector<bool>>(n + 1, vector<bool>(m + 1))); queue<tp3> q; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(a[i][j] == BLOCKED) continue; vis[0][i][j] = true; q.emplace(0, i, j); } } int counter = 0; while(!q.empty()) { int t, u, v; tie(t, u, v) = q.front(); q.pop(); // debug("State", t, u, v); if(t == k) { counter++; continue; } if(d[t + 1] != '?') { int i = direction[d[t + 1]]; int x = u + dx[i], y = v + dy[i]; // debug("Move", d[t + 1], pii(u, v), pii(x, y)); if(1 <= x && x <= n && 1 <= y && y <= m && a[x][y] != BLOCKED) { if(!vis[t + 1][x][y]) { vis[t + 1][x][y] = true; q.emplace(t + 1, x, y); } } }else { for(int i = 0; i < 4; i++) { int x = u + dx[i], y = v + dy[i]; if(1 <= x && x <= n && 1 <= y && y <= m && a[x][y] != BLOCKED) { if(!vis[t + 1][x][y]) { vis[t + 1][x][y] = true; q.emplace(t + 1, x, y); } } } } } cout << counter << endl; // debug("After board"); // for(int i = 1; i <= n; i++) { // for(int j = 1; j <= m; j++) // cerr << vis[k][i][j]; // cerr << endl; // } // debug("Ending"); } } void process() { if(subtask_2::approve()) return subtask_2::execute(); assert(false); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #define task "Deeto" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int testcase = 1; // cin >> testcase; for(int i = 1; i <= testcase; i++) { input(); process(); } cerr << "Saa, watashtachi no deeto hajimemashou" << endl; cerr << "Atarashii kiseki wo koko kara hajimeru shining place nee mou ichido kimi to..." << endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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