結果

問題 No.1109 調の判定
ユーザー bluemegane
提出日時 2024-04-06 11:04:54
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 14,691 ms
コンパイル使用メモリ 168,284 KB
実行使用メモリ 184,540 KB
最終ジャッジ日時 2024-10-01 03:48:25
合計ジャッジ時間 11,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (92 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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 w = new int[] { 0, 2, 4, 5, 7, 9, 11 };
        var hs = new HashSet<int>[12];
        for (int i = 0; i < 12; i++)
        {
            hs[i] = new HashSet<int>();
            foreach (var x in w) hs[i].Add((x + i) % 12);
        }
        var c = new List<int>();
        for (int i = 0; i < 12; i++)
        {
            var ok = true;
            foreach (var x in a)
            {
                if (!hs[i].Contains(x)) { ok = false; break; }
            }
            if (ok) c.Add(i);
        }
        if (c.Count == 1) Console.WriteLine(c[0]);
        else Console.WriteLine(-1);
    }
}
0