結果

問題 No.1765 While Shining
ユーザー tnakao0123tnakao0123
提出日時 2021-11-29 16:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 41,560 KB
実行使用メモリ 5,368 KB
最終ジャッジ日時 2023-09-15 08:37:16
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 13 ms
4,492 KB
testcase_10 AC 19 ms
5,132 KB
testcase_11 AC 16 ms
4,860 KB
testcase_12 AC 18 ms
5,036 KB
testcase_13 AC 16 ms
4,840 KB
testcase_14 AC 20 ms
5,368 KB
testcase_15 AC 19 ms
5,252 KB
testcase_16 AC 20 ms
5,184 KB
testcase_17 AC 19 ms
5,288 KB
testcase_18 AC 20 ms
5,324 KB
testcase_19 AC 19 ms
5,356 KB
testcase_20 AC 20 ms
5,360 KB
testcase_21 AC 20 ms
5,360 KB
testcase_22 AC 20 ms
5,320 KB
testcase_23 AC 20 ms
5,336 KB
testcase_24 AC 18 ms
5,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1765.cc:  No.1765 While Shining - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], dp[MAX_N][2];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ll sum = 0;
  dp[n - 1][0] = dp[n - 1][1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < 2; j++)
      dp[i][j] = (as[i] ^ j) ? 1 + dp[i + 1][j ^ 1] : 0;
    sum += dp[i][0];
  }

  printf("%lld\n", sum);
  return 0;
}
0