結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2019-09-10 19:55:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 521 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 166,284 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 16:19:20 |
合計ジャッジ時間 | 2,342 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 14 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:23:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized] 23 | cout << ans << endl; | ^~~ main.cpp:5:22: note: 'ans' was declared here 5 | int n, k, c = 0, ans; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c = 0, ans; string s; cin >> n >> k >> s; k--; if (s[k] == '(') { for (int i = k; i < n; i++) { if (s[i] == '(') c++; if (s[i] == ')') c--; if (c == 0) ans = i+1; } } else { for (int i = k; i >= 0; i--) { if (s[i] == '(') c++; if (s[i] == ')') c--; if (c == 0) ans = i+1; } } cout << ans << endl; return 0; }