結果

問題 No.2035 Tunnel
ユーザー srjywrdnprkt
提出日時 2023-05-11 00:29:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 104,212 KB
最終ジャッジ日時 2025-02-12 21:17:19
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:22: warning: ‘m’ may be used uninitialized [-Wmaybe-uninitialized]
   30 |     for (int i=N-1; i>=m+1; i--){
      |                     ~^~~~~
main.cpp:19:19: note: ‘m’ was declared here
   19 |     int N, ans=0, m;
      |                   ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    int N, ans=0, m;
    string S;
    cin >> N >> S;

    for (int i=0; i<N; i++){
        if (S[i] == '#'){
            m = i;
            break;
        }
    }

    for (int i=N-1; i>=m+1; i--){
        if (S[i] == '#') ans++;
        else ans = max(0, ans-1);
    }

    cout << ans+N-m << endl;

    return 0;
}
0