結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-02 20:55:06 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 323 bytes |
| 記録 | |
| コンパイル時間 | 1,141 ms |
| コンパイル使用メモリ | 174,724 KB |
| 実行使用メモリ | 181,124 KB |
| 最終ジャッジ日時 | 2026-04-02 22:00:56 |
| 合計ジャッジ時間 | 1,467 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:15:11: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
15 | cout<<ans<<endl;
| ^~~
main.cpp:4:19: note: 'ans' was declared here
4 | int n,k,bra=0,ans;
| ^~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,bra=0,ans;
string s;
cin>>n>>k>>s;
for(int i=k-1;(s[k-1]=='('?i<n:i>=0);(s[k-1]=='('?++i:--i)){
if(s[i]=='(')++bra;
else --bra;
if(bra==0){
ans=i+1;
break;
}
}
cout<<ans<<endl;
}