結果

問題 No.22 括弧の対応
ユーザー graph11463
提出日時 2025-04-01 19:58:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 4,068 bytes
コンパイル時間 5,885 ms
コンパイル使用メモリ 333,336 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-04-01 19:58:33
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
//vector
#define ALL(A) A.begin(), A.end()
#define RV(A) reverse(ALL(A))
#define RALL(A) A.rbegin(), A.rend()
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(RALL(A))
template<class T> inline void getSum(T& a,vector<T> b) {for(auto v:b) a+=v;}
//input
template<class T> inline void input(T& a) { cin >> a; }
template<class T> inline void input_li(T& a) {for(auto &ob:a) cin >> ob;}
template<class... T> inline void input(T&... a) { ((cin >> a), ...); }
//output
#define Yes(bo) cout << ((bo) ? "Yes":"No") << endl
#define YES(bo) cout << ((bo) ? "YES":"NO") << endl
#define yes(bo) cout << ((bo) ? "yes":"no") << endl
#define Taka(bo) cout << ((bo) ? "Takahashi":"Aoki") << endl
//other
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define sz size
#define is insert
#define ps push
#define tp top
#define ft front
#define pp pop
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
//const
#define I_MAX 2147483647
#define I_MIN -2147483647
#define UI_MAX 4294967295
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define ULL_MAX 18446744073709551615
#define Inf 1LL<<60
//type
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using Pair = pair<ll,ll>;
using vll = vector<ll>;
using mint = modint998244353;
using mint1 = modint1000000007;
using Graph_n = vector<vector<ll>>;
using Graph_w = vector<vector<Pair>>;
using Graph_s = vector<set<ll>>; //this type can erase edges
using Graph_e = vector<pair<ll,ll>>;
using Edges_n = vector<pair<ll,ll>>;
using Edges_w = vector<array<ll,3>>;
using Stack_l = stack<ll>;
using Queue_l = queue<ll>;
using Deque_l = deque<ll>;
using Prque_g = priority_queue<ll,vector<ll>,greater<ll>>;
using Prque_l = priority_queue<ll>;
//debug
#ifdef _DEBUG
#define debug(x) cerr << "dbg_var : " << #x << ": " << x << endl
#define debug2(x,y) cerr << "dbg_var : " << #x << ": " << x << " "<< #y << ": " << y << endl
#define debug3(x,y,z) cerr << "dbg_var : " << #x << ": " << x << " "<< #y << ": " << y << " " << #z << ": " << z <<endl
#define debug_v(x) cerr << "dbg_vect: " << #x << ": "; for(auto v:x) cerr << v << " "; cerr << endl
#define debug_s(x) cerr << "dbg_set : " << #x << ": {"; for(auto v:x) cerr << v << ","; cerr << "}" << endl
#define debug_p(x) cerr << "dbg_pair: " << #x << "Fir: " << x.first << " Sec: " << x.second << endl
#define debug_m(x) cerr << "dbg_map : " << #x << ": "; for(auto Ite1:x)cerr << "key: " << Ite1.first << " : " << Ite1.second << ", "; cerr<<
        endl
#define debug_l() cerr << "======================================" << endl
#else
#define debug(x)
#define debug2(x,y)
#define debug3(x,y,z)
#define debug_v(x)
#define debug_s(x)
#define debug_p(x)
#define debug_m(x)
#define debug_l()
#endif
ll GCD(ll a, ll b) {if (b == 0) return a;else return GCD(b, a % b);}
ll LCM(ll a, ll b) {return a * b/GCD(a , b);}
/*zahyou to ka*/
bool poich(ll P,ll Q){return(0<=P&&P<Q);}
bool poich2(ll i,ll j,ll H,ll W){return(poich(j,W)&&poich(i,H));}
vector<Pair> dxy{{1,0},{-1,0},{0,1},{0,-1}};
//https://algo-logic.info/calc-pow/
ll dpow(ll x, ll n,ll mod) {
ll ret = 1;
while (n > 0) {
if (n & 1) ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
ll chd21(ll N,ll i,ll j){
return N*i+j;
}
Pair chd12(ll N,ll X){
return {X/N,X%N};
}
int main(){
ll N,K;cin >> N >> K;
string S;cin >> S;
vector<ll> ans(N);
stack<ll> st;
for(ll i=0;i<N;i++){
if(S[i]==')'){
ans[st.top()]=i;
ans[i]=st.top();
st.pop();
}else{
st.push(i);
}
}
cout << ans[K-1]+1 << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0