結果
問題 | No.2035 Tunnel |
ユーザー |
![]() |
提出日時 | 2022-08-16 02:35:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 581 bytes |
コンパイル時間 | 404 ms |
コンパイル使用メモリ | 40,444 KB |
最終ジャッジ日時 | 2025-01-30 23:05:53 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d%s", &n, s); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2035.cc: No.2035 Tunnel - yukicoder*/#include<cstdio>#include<algorithm>using namespace std;/* constant */const int MAX_N = 300000;const int INF = 1 << 30;/* typedef *//* global variables */char s[MAX_N + 4];int xs[MAX_N], dp[MAX_N + 1];/* subroutines *//* main */int main() {int n;scanf("%d%s", &n, s);int m = 0;for (int i = 0; i < n; i++)if (s[i] == '#') xs[m++] = i;dp[m] = -INF;for (int i = m - 1; i >= 0; i--)dp[i] = max(dp[i + 1] + 2, n - xs[i]);printf("%d\n", dp[0]);return 0;}