結果

問題 No.22 括弧の対応
ユーザー 0w1
提出日時 2016-11-20 11:00:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 441 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 170,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:18:14
合計ジャッジ時間 2,477 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main(){
  int N, K; cin >> N >> K;
  string S; cin >> S;
  stack< int > pos;
  for( int i = 0; i < N; ++i ){
    if( S[ i ] == '(' )
      pos.emplace( i );
    else{
      if( i + 1 == K )
        cout << pos.top() + 1 << endl,
        exit( 0 );
      else if( pos.top() + 1 == K )
        cout << i + 1 << endl,
        exit( 0 );
      else
        pos.pop();
    }
  }
  return 0;
}
0