結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-07-26 20:15:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 707 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 157,908 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:02:51 |
合計ジャッジ時間 | 2,322 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repi(i,0,n) int n, k, d; string s; int solve() { k--; int l = k, r = k, d = 1; if(s[k] == '(') { r++; while(d) { if(s[r++] == '(') d++; else d--; } return r; } else { l--; while(d) { if(s[l--] == ')') d++; else d--; } return l+2; } return 0; } void input() { cin >> n >> k >> s; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); input(); cout << solve() << endl; return 0; }