結果

問題 No.22 括弧の対応
ユーザー ngtkana
提出日時 2020-03-05 16:11:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 299 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 166,148 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:48:09
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
int main(){
    int n,k;std::cin>>n>>k;k--;
    std::string s;std::cin>>s;
    int di=s.at(k)=='('?1:-1;
    for(int i=k,x=0;0<=i&&i<n;i+=di){
        x+=s.at(i)==s.at(k)?1:-1;
        if(x==0){
            std::cout<<i+1<<std::endl;
            return 0;
        }
    }
}

0