結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2017-09-17 20:59:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 716 bytes |
コンパイル時間 | 1,738 ms |
コンパイル使用メモリ | 167,740 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 07:25:41 |
合計ジャッジ時間 | 2,458 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ul; typedef signed long long ll; ul over = 1000000007; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; ll n, k; string s; cin >> n >> k >> s; k--; ll depth[n]; depth[0] = 1; for (int i = 1; i < n; ++i) { if (s[i] != s[i-1]) depth[i] = depth[i-1]; else if (s[i] == '(') depth[i] = depth[i-1]+1; else depth[i] = depth[i-1]-1; } if (s[k]=='(') { for (ll i = k+1; i < n; ++i) { if (depth[i]==depth[k]) {cout << i+1 << endl; return 0;} } } else { for (ll i = k-1; i >= 0; --i) { if (depth[i]==depth[k]) {cout << i+1 << endl; return 0;} } } return 0; }