結果

問題 No.592 括弧の対応 (2)
ユーザー kcz146kcz146
提出日時 2017-11-27 19:23:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 414 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 23,040 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-05-05 13:32:45
合計ジャッジ時間 1,128 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 19 ms
6,940 KB
testcase_02 AC 19 ms
6,940 KB
testcase_03 AC 19 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#include<cstdio>

char s[300000];
int prevd[300000];
int map[300000];

int main(void) {
    int n;
    scanf("%d",&n);
    scanf("%s",s);

    int d=0;
    for(int i=0; i<n; i++)
        if(s[i]=='(') {
            prevd[d] = i;
            d++;
        } else {
            d--;
            map[i] = prevd[d];
            map[prevd[d]] = i;
        }
    for(int i=0; i<n; i++)
        printf("%d\n", map[i]+1);
}
0