結果
問題 |
No.3210 Fixed Sign Sequense
|
ユーザー |
![]() |
提出日時 | 2025-07-27 18:51:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 745 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 41,944 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-27 18:51:12 |
合計ジャッジ時間 | 1,615 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d%s", &n, s); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3210.cc: No.3210 Fixed Sign Sequense - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 300000; /* typedef */ /* global variables */ char s[MAX_N + 4]; int mcs[MAX_N + 1], pcs[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); for (int i = 0; i < n; i++) mcs[i + 1] = mcs[i] + (s[i] == '-' ? 1 : 0); for (int i = n - 1; i >= 0; i--) pcs[i] = pcs[i + 1] + (s[i] == '+' ? 1 : 0); int maxl = 0; for (int i = 0; i <= n; i++) maxl = max(maxl, mcs[i] + pcs[i]); for (int i = 0; i < n; i++) if (s[i] == '0') maxl = max(maxl, mcs[i] + 1 + pcs[i + 1]); printf("%d\n", maxl); return 0; }