結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-05 17:09:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 239 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:34:01 |
| 合計ジャッジ時間 | 838 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | scanf("%d %d",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%s",S);
| ~~~~~^~~~~~~~
ソースコード
#include <stdio.h>
int main(){
int N,K;
scanf("%d %d",&N,&K);
char S[10000+1];
scanf("%s",S);
int level = 0;
int buffer[10000];
for (int i = 0;i < N;i++){
if (S[i] == '('){
level++;
buffer[i] = level;
}else{
buffer[i] = level;
level--;
}
}
if (S[K-1] == '('){
for (int i = K;i < N;i++){
if (buffer[i] == buffer[K-1]){
printf("%d\n",i+1);
break;
}
}
}else{
for (int i = K-2;i >= 0;i--){
if (buffer[i] == buffer[K-1]){
printf("%d\n",i+1);
break;
}
}
}
}