結果

問題 No.22 括弧の対応
ユーザー focus
提出日時 2018-02-16 23:49:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 68,868 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-20 07:29:28
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int N,K,count=0;
    string s;
    cin >> N >> K >> s;
    if(s[K-1]=='('){
        for(int i=K;i<N;i++){
            if(s[i]==')'){
               if(count==0){
                    cout << i+1;
                    return 0;
               }
               count--;
            }
            else{
                 count++;
            }
        }
    }
    else{
        for(int i=K-2;i>=0;i--){
            if(s[i]=='('){
               if(count==0){
                    cout << i+1;
                    return 0;
               }
               count--;
            }
            else{
                 count++;
            }
        }
    }
    return 0;
}
0