結果

問題 No.22 括弧の対応
ユーザー Darsein
提出日時 2015-05-03 19:20:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 348 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 61,788 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 06:59:54
合計ジャッジ時間 1,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  int n,k;
  cin >> n >> k; k--;

  string s;
  cin >> s;
  stack<int> p;

  for(int i=0;i<n;i++){
    if(s[i] == '('){
      p.push(i);
    }else{
      if(i==k){
	cout << p.top()+1 << endl;
      }
      if(p.top()==k){
	cout << i+1 << endl;
      }
      p.pop();
    }
  }
}
0