結果
| 問題 | No.1594 Three Classes |
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2021-07-10 10:44:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,147 bytes |
| 記録 | |
| コンパイル時間 | 898 ms |
| コンパイル使用メモリ | 107,136 KB |
| 実行使用メモリ | 434,432 KB |
| 最終ジャッジ日時 | 2024-07-02 01:49:29 |
| 合計ジャッジ時間 | 4,382 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 1 TLE * 1 -- * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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]);
}
}
bluemegane