結果
問題 |
No.608 God's Maze
|
ユーザー |
![]() |
提出日時 | 2017-12-08 09:11:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 880 bytes |
コンパイル時間 | 2,122 ms |
コンパイル使用メモリ | 195,600 KB |
最終ジャッジ日時 | 2025-01-05 04:54:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 61 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int solve(string S, int N) { int right = -1, ret = 0; for(int i = N; i >= 0; i--) { if(S[i] == '#') right = i; } if(right == -1) return (INF); for(int i = N - 1; i >= right; i--) { S[i] = ".#"[S[i] == '.']; ++ret; } S += "."; int rest = count(begin(S), end(S), '#'); while(rest > 0) { ++right; assert(right < S.size()); ++ret; S[right] = ".#"[S[right] == '.']; if(S[right] == '.') rest--; else rest++; if(S[right - 1] == '#') { --right; ++ret; S[right] = ".#"[S[right] == '.']; if(S[right] == '.') rest--; else rest++; } } return (ret); } int main() { int N; string S, T; cin >> N; cin >> S; T = S; reverse(begin(T), end(T)); cout << min(solve(S, N - 1), solve(T, (int) S.size() - N)) << endl; }