結果

問題 No.1594 Three Classes
ユーザー bluemeganebluemegane
提出日時 2021-07-10 10:44:15
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,147 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 67,468 KB
実行使用メモリ 446,272 KB
最終ジャッジ日時 2023-09-14 18:47:56
合計ジャッジ時間 4,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
25,684 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int t { get; set; }
    public string s { get; set; }
}

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);
        if (a.Sum() % n != 0) Console.WriteLine("No");
        else getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var q = new Queue<P>();
        q.Enqueue(new P { s = "", t = 0 });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.t == n && check(w.s, n, a)) { Console.WriteLine("Yes"); return; }
            for (int i = 0; i < 3; i++)
            {
                q.Enqueue(new P { s = w.s + i.ToString(), t = w.t + 1 });
            }
        }
        Console.WriteLine("No");
    }
    static bool check(string s, int n, int[] a)
    {
        var sum = new int[3];
        for (int i = 0; i < n; i++)
            sum[s[i] - '0'] += a[i];
        return (sum[0] == sum[1] && sum[1] == sum[2]);
    }
}
0