結果
| 問題 | 
                            No.22 括弧の対応
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-01-06 16:39:31 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 456 bytes | 
| コンパイル時間 | 693 ms | 
| コンパイル使用メモリ | 71,036 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-20 07:38:11 | 
| 合計ジャッジ時間 | 1,891 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef pair<char, int> PCI;
int main(void){
  int n,k;
  vector<PCI> stk;
  char c;
  
  cin >> n >> k;
  for (int i=1; i<=n; i++){
    cin >> c;
    if (c=='(') stk.push_back(make_pair(c,i));
    else { // c==')'
      PCI pci = stk.back();
      if (i==k) cout << pci.second << endl;
      if (pci.second==k) cout << i << endl;
      stk.pop_back();
    }
  }
  return 0;
}