結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2020-11-12 11:39:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 660 bytes |
コンパイル時間 | 1,684 ms |
コンパイル使用メモリ | 167,788 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 19:09:51 |
合計ジャッジ時間 | 2,560 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,K; cin >> N >> K; K--; string s; cin >> s; bool r = false; if(s[K] == ')'){ r = true; reverse(s.begin(), s.end()); rep(i,s.size()){ if(s[i] == ')') s[i] = '('; else s[i] = ')'; } K = N - K - 1; } int c = 0; for(int i=K;i<N;i++){ if(s[i] == '(') c++; else c--; if(c == 0){ cout << (r?N - i:i + 1) << endl; return 0; } } }