結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2017-06-17 01:00:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 889 bytes |
コンパイル時間 | 879 ms |
コンパイル使用メモリ | 93,900 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:24:23 |
合計ジャッジ時間 | 1,824 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define PI acos(-1.0) #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; typedef pair<char, int> P; int main(){ int n, k; cin >> n >> k; string s; cin >> s; stack<P> st; st.push(P(s[0], 1)); FOR(i,1,n){ if(s[i]=='(') st.push(P(s[i], i+1)); else { P p = st.top();st.pop(); if(p.second == k){ cout << i + 1 << endl; return 0; } else if(i + 1 == k){ cout << p.second << endl; return 0; } } } return 0; }