結果
| 問題 |
No.684 Prefix Parenthesis
|
| コンテスト | |
| ユーザー |
square1001
|
| 提出日時 | 2018-05-28 22:24:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 693 bytes |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 32,512 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 07:52:58 |
| 合計ジャッジ時間 | 1,140 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 WA * 2 |
ソースコード
#include <cstdio>
int n, d, mn, ca[100009], cb[100009]; long long sum, curl, depl, curr, depr; bool fa[100009], fb[100009]; char s;
int main() {
scanf("%d\n", &n);
for (int i = 0; i < n; ++i) {
s = getchar();
d += (s == '(' ? 1 : -1);
sum += d;
mn = (mn < d ? mn : d);
if (d >= 0) ca[-mn] += d, fa[-mn] = true;
else cb[d - mn] -= d, fb[d - mn] = true;
}
for (int i = 0; i <= n; ++i) {
if (fa[i]) depl = (depl < curl - i ? depl : curl - i);
curl += ca[i];
}
for (int i = 0; i <= n; ++i) {
if (fb[i]) depr = (depr < curr - i ? depr : curr - i);
curr += cb[i];
}
printf("%lld\n", 1LL * n * (n + 1) / 2 + (depl < depr + sum ? depl : depr + sum) * 2 - sum);
return 0;
}
square1001