結果

問題 No.2035 Tunnel
ユーザー Cyanmond
提出日時 2022-08-12 21:34:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 192,520 KB
最終ジャッジ日時 2025-01-30 20:50:02
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;
    int last_pos = N + 1, last_wt = 0;
    int answer = 0;
    for (int i = N - 1; i >= 0; --i) {
        if (S[i] == '.') continue;
        int new_wt = 0;
        if (last_pos == i + 1) {
            new_wt = last_wt + 1;
        } else {
            if (i + last_wt + 1 < last_pos) new_wt = 0;
            else new_wt = last_wt - (last_pos - i) + 2;
        }
        answer = std::max(answer, N - i + new_wt);
        last_pos = i;
        last_wt = new_wt;
    }
    std::cout << answer << std::endl;
}
0