結果

問題 No.22 括弧の対応
ユーザー Bantako
提出日時 2017-06-28 18:49:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 23,040 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 14:52:35
合計ジャッジ時間 712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
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