結果

問題 No.608 God's Maze
ユーザー Pachicobue
提出日時 2017-12-13 19:38:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 196,412 KB
最終ジャッジ日時 2025-01-05 05:13:07
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    N--;
    string S;
    cin >> S;
    const int size = S.size();
    vector<bool> need(size);
    for (int i = 0; i < size; i++) {
        need[i] = S[i] == '#';
    }
    int left = size;
    int right = 0;
    for (int i = 0; i < size; i++) {
        if (need[i]) {
            left = min(left, i);
            right = max(right, i);
        }
    }
    ll ans = 0;
    for (int i = left; i < N; i++) {
        ans++;
        need[i] = not need[i];
        if (need[i]) {
            right = max(right, i);
        }
    }
    for (int i = left; i < right; i++) {
        ans++;
        need[i + 1] = not need[i + 1];
        if (need[i]) {
            ans += (i == right - 1 ? 1 : 2);
            need[i + 1] = (i == right - 1 ? need[i + 1] : not need[i + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}
0