結果

問題 No.1765 While Shining
ユーザー bluemeganebluemegane
提出日時 2021-11-27 10:07:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,675 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 63,556 KB
実行使用メモリ 40,004 KB
最終ジャッジ日時 2023-09-12 13:19:50
合計ジャッジ時間 5,026 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,780 KB
testcase_01 AC 57 ms
20,720 KB
testcase_02 AC 59 ms
22,596 KB
testcase_03 AC 57 ms
22,656 KB
testcase_04 WA -
testcase_05 AC 65 ms
20,840 KB
testcase_06 AC 66 ms
22,920 KB
testcase_07 AC 65 ms
20,876 KB
testcase_08 AC 67 ms
20,744 KB
testcase_09 AC 96 ms
28,936 KB
testcase_10 AC 119 ms
37,716 KB
testcase_11 AC 105 ms
30,404 KB
testcase_12 AC 117 ms
37,608 KB
testcase_13 AC 105 ms
30,244 KB
testcase_14 AC 121 ms
35,900 KB
testcase_15 AC 122 ms
35,916 KB
testcase_16 AC 122 ms
37,936 KB
testcase_17 AC 122 ms
38,008 KB
testcase_18 AC 122 ms
40,004 KB
testcase_19 AC 122 ms
38,116 KB
testcase_20 AC 122 ms
37,992 KB
testcase_21 AC 121 ms
35,940 KB
testcase_22 WA -
testcase_23 AC 122 ms
38,060 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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 && now == 1) ans.Add(tc - 1);
        if (flag && now == 0) ans.Add(tc );
        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