結果
| 問題 | No.1765 While Shining | 
| コンテスト | |
| ユーザー |  bluemegane | 
| 提出日時 | 2021-11-27 10:15:23 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 87 ms / 2,000 ms | 
| コード長 | 1,620 bytes | 
| コンパイル時間 | 2,041 ms | 
| コンパイル使用メモリ | 112,200 KB | 
| 実行使用メモリ | 33,536 KB | 
| 最終ジャッジ日時 | 2024-06-30 01:42:19 | 
| 合計ジャッジ時間 | 4,525 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
    }
}
            
            
            
        