結果

問題 No.22 括弧の対応
ユーザー BantakoBantako
提出日時 2017-06-28 18:49:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 23,040 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 04:05:25
合計ジャッジ時間 901 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 0 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 0 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 0 ms
6,940 KB
testcase_13 AC 0 ms
6,940 KB
testcase_14 WA -
testcase_15 AC 0 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:3:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    3 | main(){
      | ^~~~
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 %s",&N,&K,S);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
char S[10001];
main(){
    int N,K;
    scanf("%d %d %s",&N,&K,S);
    int count = 0;//(:+1 ):-1
    if(K < N/2){    //前半の場合
        for(int i = K-1;i < N;i++){
            count += S[i]=='('?1:-1;
            if(count == 0){
                printf("%d\n",i+1);
                return 0;
            }
        }
    }else{
        for(int i = K-1;i >= 0;i--){
            count += S[i]=='('?1:-1;
            if(count == 0){
                printf("%d\n",i+1);
                return 0;
            }
        }
    }
}
0