結果

問題 No.2035 Tunnel
ユーザー SSRS
提出日時 2022-08-12 21:26:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 167,504 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-23 00:47:57
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int l = -1;
  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '#'){
      if (l == -1){
        l = i;
      }
    }
  }
  for (int i = N - 1; i >= l; i--){
    if (S[i] == '#'){
      cnt++;
    } else {
      cnt = max(cnt - 1, 0);
    }
  }
  cout << N - l + cnt - 1 << endl;
}
0