結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-05 16:05:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 603 bytes |
| コンパイル時間 | 1,547 ms |
| コンパイル使用メモリ | 166,532 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:47:59 |
| 合計ジャッジ時間 | 2,286 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:21:19: warning: 'y' may be used uninitialized [-Wmaybe-uninitialized]
21 | if(i<k&&x==y){
| ~~~^~~~~~
main.cpp:5:13: note: 'y' was declared here
5 | int x=0,y;
| ^
ソースコード
#include<bits/stdc++.h>
int main(){
int n,k;std::cin>>n>>k;k--;
std::string s;std::cin>>s;
int x=0,y;
if(s.at(k)=='('){
for(int i=0;i<n;i++){
if(i==k)y=x;
x+=s.at(i)=='('?1:-1;
if(k<i&&x==y){
std::cout<<i+1<<std::endl;
return 0;
}
}
}
x=0;
if(s.at(k)==')'){
for(int i=n-1;i>=0;i--){
if(i==k)y=x;
x+=s.at(i)=='('?1:-1;
if(i<k&&x==y){
std::cout<<i+1<<std::endl;
return 0;
}
}
}
}
ngtkana