結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
kosakkun
|
| 提出日時 | 2017-04-11 17:51:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,337 bytes |
| コンパイル時間 | 1,127 ms |
| コンパイル使用メモリ | 102,252 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:20:58 |
| 合計ジャッジ時間 | 1,524 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
int main(){
int N,K; cin >> N >> K;
string S; cin >> S;
vector<int> p(N+1);
stack< pair<int,int> > sta;
REP(i,S.size()){
if(sta.size()==0)sta.push(make_pair(S[i],i+1));
else{
if(S[i]=='(')sta.push(make_pair(S[i],i+1));
else{
int idx = sta.top().second;
sta.pop();
p[i+1] = idx;
p[idx] = i+1;
}
}
}
cout << p[K] << endl;
return 0;
}
kosakkun