結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-07-24 07:36:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 672 bytes |
コンパイル時間 | 1,398 ms |
コンパイル使用メモリ | 164,464 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 12:49:37 |
合計ジャッジ時間 | 1,762 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, K; cin >> N >> K; string s; cin >> s; int first = 0; int pcnt = 1; stack<pair<char, int>> stack; vector<int> pindex(N); pindex[0] = 1; stack.push(make_pair(s[first++], 1)); while(!stack.empty()){ if(s[first] == '('){ pcnt++; stack.push(make_pair(s[first], pcnt)); } else if(s[first] == ')'){ auto index = stack.top(); stack.pop(); pindex[first] = index.second; pindex[index.second] = first; } first++; } cout << pindex[K-1] << endl; return 0; }