結果

問題 No.22 括弧の対応
ユーザー Kura
提出日時 2019-07-11 08:17:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 419 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 158,460 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:43:32
合計ジャッジ時間 1,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;string s;
  cin>>n>>m>>s;
  int c=0;
  if(s[m-1]=='('){
    for(int i=m;i<n;i++){
      if(s[i]=='(')c++;
      else c--;
      if(c==-1){
        cout<<i+1<<endl;
        return 0;
      }
    }
  }else{
    for(int i=m-2;i>=0;i--){
      if(s[i]=='(')c++;
      else c--;
      if(c==1){
        cout<<i+1<<endl;
        return 0;
      }
    }
  }
}
0