結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-01-15 15:56:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 724 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 83,816 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 06:56:15 |
合計ジャッジ時間 | 1,440 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <iostream> #include <map> #include <list> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <vector> #include <algorithm> #include <utility> #include <queue> #include <iomanip> #define INF 1050000000 using namespace std; int main(void) { int N, K; string S; int d = 0; cin >> N >> K; cin >> S; if(S[K - 1] == '(') { for (int i = K - 1; i < N; i++) { if (S[i] == '(') d++; else d--; if(d == 0) { cout << i + 1 << endl; break; } } } else { for (int i = K - 1; i >= 0; i--) { if (S[i] == ')') d++; else d--; if(d == 0) { cout << i + 1 << endl; break; } } } }