結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-27 16:48:44 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 770 bytes |
| コンパイル時間 | 3,253 ms |
| コンパイル使用メモリ | 258,232 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 07:46:04 |
| 合計ジャッジ時間 | 3,911 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define ar array
#define sz(x) ((int)x.size())
template <class T,class S> inline bool chmin(T &a,const S &b) {return (a> b? a= b, 1: 0);}
template <class T,class S> inline bool chmax(T &a,const S &b) {return (a< b? a= b, 1: 0);}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
stack <int> st;
st.push(1);
map <int, int> mp;
for(int i = 1;i < sz(s);i++){
if(s[i] == ')'){
mp[i + 1] = st.top();
mp[st.top()] = i + 1;
st.pop();
}
else{
st.push(i + 1);
}
}
cout << mp[k] << "\n";
return 0;
}