結果
問題 | No.22 括弧の対応 |
ユーザー | Kutimoti_T |
提出日時 | 2017-12-18 17:52:18 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 408 bytes |
コンパイル時間 | 457 ms |
コンパイル使用メモリ | 64,756 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:28:34 |
合計ジャッジ時間 | 1,092 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <queue> #include <stack> #define FOR(i,s,e) for(int i = (s);i <= (e);i++) using namespace std; int N,K; string S; int memo[10000]; int main() { cin >> N >> K; cin >> S; stack<int> s; FOR(i,0,N - 1) { if(S[i] == '(') { s.push(i); } else { int x = s.top(); s.pop(); memo[x] = i; memo[i] = x; } } cout << memo[K - 1] + 1 << endl; return 0; }