結果
| 問題 |
No.3210 Fixed Sign Sequense
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-25 21:37:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 913 bytes |
| コンパイル時間 | 1,969 ms |
| コンパイル使用メモリ | 196,124 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-25 21:37:26 |
| 合計ジャッジ時間 | 3,445 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#define dbgn(...) 0
#endif
void solve() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> np(n + 1, 0);
for (int i = 0; i < n; i++) {
np[i + 1] = np[i] + (s[i] == '-' ? 1 : 0);
}
vector<int> ps(n + 1, 0);
for (int i = n - 1; i >= 0; i--) {
ps[i] = ps[i + 1] + (s[i] == '+' ? 1 : 0);
}
int ans = 0;
for (int i = 0; i <= n; i++) {
int c = np[i] + ps[i];
if (c > ans) {
ans = c;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
int c = np[i] + 1 + ps[i + 1];
if (c > ans) {
ans = c;
}
}
}
cout << ans << '\n';
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
solve();
return 0;
}