結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-12-30 22:34:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 645 ms |
コンパイル使用メモリ | 76,788 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:06:41 |
合計ジャッジ時間 | 1,383 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <vector> #include <list> #include <deque> #include <stack> #include <map> #include <algorithm> #include <cmath> using namespace std; #define FOR(x,y) for(int x = 0;x < y;x++) #define LLI long long int template<int um> class UF { public: vector<int> par,rank,cnt; UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;} void reinit() {FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;} int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));} int count(int x) { return cnt[operator[](x)];} int operator()(int x,int y) { if((x=operator[](x))==(y=operator[](y))) return x; cnt[y]=cnt[x]=cnt[x]+cnt[y]; if(rank[x]>rank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; int main() { int n,k; cin >> n >> k; stack<int> buffer; FOR(i, n) { char c; cin >> c; if(c == '(') { buffer.push(i); } else { int front = buffer.top(); buffer.pop(); if(front + 1 == k) { cout << i + 1 << endl; return 0; } else if(i + 1 == k) { cout << front + 1 << endl; return 0; } } } return 0; }