結果

問題 No.1765 While Shining
ユーザー bluemeganebluemegane
提出日時 2021-11-27 10:15:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,620 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 61,640 KB
実行使用メモリ 40,084 KB
最終ジャッジ日時 2023-09-12 13:28:10
合計ジャッジ時間 5,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,620 KB
testcase_01 AC 58 ms
20,816 KB
testcase_02 AC 58 ms
20,732 KB
testcase_03 AC 58 ms
18,560 KB
testcase_04 AC 65 ms
20,888 KB
testcase_05 AC 66 ms
20,956 KB
testcase_06 AC 66 ms
20,820 KB
testcase_07 AC 66 ms
22,900 KB
testcase_08 AC 66 ms
20,832 KB
testcase_09 AC 96 ms
26,920 KB
testcase_10 AC 120 ms
33,576 KB
testcase_11 AC 104 ms
28,220 KB
testcase_12 AC 117 ms
35,360 KB
testcase_13 AC 104 ms
28,220 KB
testcase_14 AC 123 ms
36,024 KB
testcase_15 AC 123 ms
36,048 KB
testcase_16 AC 122 ms
35,936 KB
testcase_17 AC 122 ms
38,012 KB
testcase_18 AC 123 ms
37,996 KB
testcase_19 AC 124 ms
40,084 KB
testcase_20 AC 122 ms
36,008 KB
testcase_21 AC 124 ms
35,960 KB
testcase_22 AC 124 ms
36,016 KB
testcase_23 AC 124 ms
35,932 KB
testcase_24 AC 119 ms
36,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n,a);    
    }
    static void getAns(int n,int[]a)
    {
        var ans = new List<long>();
        var now = a[0];
        var flag = now== 1? true: false;
        var tc = flag ? 1 : 0;
        for (int i = 1; i < n; i++)
        {
            if (flag)
            {
                if (now == 1)
                {
                    if (a[i] == 0) { tc++;  now = 0; }
                    else
                    {
                        ans.Add(tc);
                        tc = 1;
                        flag = true;
                        now = 1;
                    }
                }
                else
                {
                    if (a[i] == 1) { tc++; now = 1; }
                    else
                    {
                        ans.Add(tc);
                        tc = 0;
                        flag = false;
                        now = 0;
                    }
                }
            }
            else
            {
                if (a[i] == 1) { flag = true; tc++;  now = 1; }
                else now = 0;
            }
        }
        if (flag ) ans.Add(tc - 1);
        var res = 0L;
        foreach(var x in ans)
        {
            if (x % 2 == 0) res += (x / 2) * (x / 2 + 1);
            else res += (x + 1) * (x + 1) / 4L;
        }
        Console.WriteLine(res);
    }
}
0