結果
| 問題 |
No.1765 While Shining
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2021-11-27 09:33:37 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,631 bytes |
| コンパイル時間 | 692 ms |
| コンパイル使用メモリ | 105,216 KB |
| 実行使用メモリ | 33,664 KB |
| 最終ジャッジ日時 | 2024-06-30 01:20:50 |
| 合計ジャッジ時間 | 3,230 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 3 |
コンパイルメッセージ
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 && now == 1) 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);
}
}
bluemegane