結果

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