Submission #1092045


Source Code Expand

Copy
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;

class Myon
{
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    public bool calc2()
    {

        int N = cin.nextInt();
        long[] num = new long[N];
        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            num[i] = cin.nextLong();
            sum += num[i];
        }
        long div = N * (long)(N + 1) / 2;
        if (sum % div != 0) return false;
        long need = sum / div;
        long cnt = 0;

        for (int i = 0; i < N; i++)
        {
            long diff = num[i] - (num[(i + N - 1) % N] + need);
            if (diff > 0) return false;
            if (diff == 0) continue;
            if ((-diff) % N != 0) return false;
            long add = (-diff) / N;
            cnt += add;
            if (num[i] < add) return false; 
        }
        if (cnt != need) return false;
        return true;

    }

    public void calc()
    {
        if (calc2()) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }
    
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Submission Info

Submission Time
Task B - Boxes
User chokudai
Language C# (Mono 4.6.2.0)
Score 500
Code Size 2063 Byte
Status
Exec Time 73 ms
Memory 16344 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1.txt, sample2.txt, sample3.txt
All 500 / 500 sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt
Case Name Status Exec Time Memory
in1.txt 66 ms 15192 KB
in10.txt 24 ms 4312 KB
in11.txt 71 ms 16344 KB
in12.txt 72 ms 16344 KB
in13.txt 62 ms 14168 KB
in14.txt 18 ms 2648 KB
in15.txt 18 ms 2648 KB
in16.txt 18 ms 2648 KB
in17.txt 18 ms 2648 KB
in18.txt 18 ms 2648 KB
in19.txt 18 ms 2648 KB
in2.txt 72 ms 16344 KB
in20.txt 18 ms 2648 KB
in21.txt 73 ms 16344 KB
in22.txt 72 ms 16344 KB
in23.txt 72 ms 16344 KB
in24.txt 21 ms 3416 KB
in25.txt 23 ms 4312 KB
in26.txt 72 ms 16216 KB
in27.txt 71 ms 16344 KB
in3.txt 72 ms 16344 KB
in4.txt 72 ms 16344 KB
in5.txt 72 ms 16344 KB
in6.txt 72 ms 16344 KB
in7.txt 71 ms 16344 KB
in8.txt 23 ms 4184 KB
in9.txt 24 ms 4312 KB
sample1.txt 18 ms 2648 KB
sample2.txt 18 ms 2648 KB
sample3.txt 18 ms 2648 KB