結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
yuruhiya
|
| 提出日時 | 2019-05-01 10:09:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,490 bytes |
| コンパイル時間 | 1,714 ms |
| コンパイル使用メモリ | 165,588 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:42:26 |
| 合計ジャッジ時間 | 2,482 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);
template<class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template<class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template<class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template<class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template<class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template<class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template<class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template<class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }
template<class T>T Age(T a, T b) { return (a + b - 1) / b; }
int main() {
int n, k; cin >> n >> k;
string s; cin >> s;
k--;
int ans = 0;
int d = s[k] == '(' ? 1 : -1;
int cnt = 1, pos = k;
while (cnt != 0) {
pos += d;
cnt += s[pos] == '(' ? d : -d;
}
cout << pos + 1 << endl;
}
yuruhiya