結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
chiyoda
|
| 提出日時 | 2016-06-26 11:10:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 572 bytes |
| コンパイル時間 | 325 ms |
| コンパイル使用メモリ | 50,280 KB |
| 最終ジャッジ日時 | 2024-11-14 19:45:29 |
| 合計ジャッジ時間 | 827 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:14: error: invalid types ‘int[int]’ for array subscript
19 | if (cnt[k - 1] - 1 == cnt[i]) {
| ^
main.cpp:19:32: error: invalid types ‘int[int]’ for array subscript
19 | if (cnt[k - 1] - 1 == cnt[i]) {
| ^
main.cpp:26:14: error: invalid types ‘int[int]’ for array subscript
26 | if (cnt[k - 1] + 1 == cnt[i]) {
| ^
main.cpp:26:32: error: invalid types ‘int[int]’ for array subscript
26 | if (cnt[k - 1] + 1 == cnt[i]) {
| ^
ソースコード
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
int sum[n] = {};
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') cnt++;
else cnt--;
sum[i] = cnt;
}
int res;
if (s[k -1] == '(') {
for (int i = k; i < n; ++i) {
if (cnt[k - 1] - 1 == cnt[i]) {
res = i + 1;
break;
}
}
} else {
for (int i = k - 2; i >= 0; --i) {
if (cnt[k - 1] + 1 == cnt[i]) {
res = i + 1;
}
}
}
cout << res << endl;
return 0;
}
chiyoda