結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
Xelmeph
|
| 提出日時 | 2017-01-03 00:44:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 790 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 73,888 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:19:14 |
| 合計ジャッジ時間 | 1,360 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
template<typename STL> inline void print_STL(STL c, string ab = ""){
cout << ab << '\n';
for(auto t : c) cout << t << ' '; cout << '\n';}
template<typename VEC> inline void import_VEC(VEC& c, int n){
typename VEC::value_type tmp;
for(int i = 0; i < n; ++i){ cin >> tmp; c.push_back(tmp);} }
#define SPRE(x) setprecision(x) // 精度を指定
int solve(const string& s, int i, int k)
{
int add = 0;
if(s[i] == '(')
add = 1;
else
add = -1;
k += add;
add = k > 0 ? 1 : -1;
return k == 0 ? i : solve(s, i + add, k);
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
string s;
cin >> s;
k--;
cout << solve(s, k, 0) + 1 << '\n';
}
Xelmeph