結果
問題 |
No.1765 While Shining
|
ユーザー |
![]() |
提出日時 | 2024-06-12 16:59:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 607 bytes |
コンパイル時間 | 2,030 ms |
コンパイル使用メモリ | 197,540 KB |
最終ジャッジ日時 | 2025-02-21 21:19:09 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> dp(n, vector<int>(2)); for (int i = n - 2; i >= 0; i--) { for (int j = 0; j < 2; j++) { if (a[i] ^ j) { dp[i][j] = dp[i + 1][!j] + 1; } } } long long ans = 0; for (int i = 0; i < n; i++) { ans += dp[i][0]; } cout << ans << endl; }