結果

問題 No.22 括弧の対応
ユーザー おきょん.おきょん.
提出日時 2022-01-05 21:19:36
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,844 bytes
コンパイル時間 4,251 ms
コンパイル使用メモリ 258,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 05:34:28
合計ジャッジ時間 5,128 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.22 括弧の対応
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl;
#define ENDL cout << endl;
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    int n , k; cin >> n >> k;
    string s; cin >> s;
    VI table(n);
    int i = 0;
    while( s[0] =='(' || s[n-1] == ')' ){
        if( s[i] == 'B' ) { ++i; continue; }
        else if(s[i] == ')'){
            if( s[i-1] == '('){
                s[i] = 'B'; s[i-1] = 'B';
                table[i] = i-1; table[i-1] = i;
                ++i;
            } else {
                for( int j = i -1 ; j >= 0 ; --j ){
                    if( s[j] =='('){
                        s[i] = 'B'; s[j] = 'B';
                        table[i] = j; table[j] = i;
                        ++i;
                        break;
                    }
                }
            }
        } else { ++i; }
    }
    
    /*
    cout << s << endl;
    for ( auto && c : table){
        cout << c << " ";
    }
    ENDL
    */
    
   cout << table[k - 1] + 1 << endl;
}
0