結果

問題 No.1765 While Shining
ユーザー kokatsukokatsu
提出日時 2021-11-26 22:58:30
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 205,972 KB
実行使用メモリ 11,364 KB
最終ジャッジ日時 2023-09-04 15:08:23
合計ジャッジ時間 3,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 14 ms
8,184 KB
testcase_10 AC 18 ms
8,620 KB
testcase_11 AC 17 ms
8,792 KB
testcase_12 AC 18 ms
10,140 KB
testcase_13 AC 16 ms
8,508 KB
testcase_14 AC 19 ms
9,840 KB
testcase_15 AC 19 ms
11,364 KB
testcase_16 AC 20 ms
10,764 KB
testcase_17 AC 19 ms
10,676 KB
testcase_18 AC 20 ms
10,640 KB
testcase_19 AC 19 ms
9,844 KB
testcase_20 AC 20 ms
10,876 KB
testcase_21 AC 19 ms
11,108 KB
testcase_22 AC 19 ms
10,636 KB
testcase_23 AC 19 ms
10,428 KB
testcase_24 AC 19 ms
10,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto A = readln.chomp.split.to!(int[]);

    long f(long cnt) {
        long l = (cnt + 1) / 2;
        return l * (cnt - l + 1);
    }

    long res, cnt;
    bool isMoving;
    foreach (i; 0 .. N-1) {
        if (A[i] == 1) {
            if (isMoving) {
                if (cnt % 2 == 0) {
                    ++cnt;
                }
                else {
                    res += f(cnt);
                    cnt = 1;
                }
            }
            else {
                isMoving = true;
                ++cnt;
            }
        }
        else {
            if (isMoving) {
                if (cnt % 2 == 1) {
                    ++cnt;
                }
                else {
                    res += f(cnt);
                    isMoving = false;
                    cnt = 0;
                }
            }
        }
    }
    res += f(cnt);

    res.writeln;
}
0