結果
| 問題 |
No.153 石の山
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-02 17:03:36 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 5,000 ms |
| コード長 | 1,916 bytes |
| コンパイル時間 | 13,452 ms |
| コンパイル使用メモリ | 166,304 KB |
| 実行使用メモリ | 185,940 KB |
| 最終ジャッジ日時 | 2024-07-02 17:03:53 |
| 合計ジャッジ時間 | 14,134 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (84 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/
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
static int[] memo = { };
static int GetGrundy(int count)
{
if(memo[count] != -1)
return memo[count];
Dictionary<int, int> dic = new Dictionary<int, int>();
if (count >= 2 && count % 2 == 0)
{
int grundy = GetGrundy(count / 2) ^ GetGrundy(count / 2);
if(!dic.ContainsKey(grundy))
dic.Add(grundy, 1);
}
if (count >= 2 && count % 2 == 1)
{
int grundy = GetGrundy(count / 2) ^ GetGrundy(count / 2 + 1);
if (!dic.ContainsKey(grundy))
dic.Add(grundy, 1);
}
if (count >= 3 && count % 3 == 0)
{
int grundy = GetGrundy(count / 3) ^ GetGrundy(count / 3) ^ GetGrundy(count / 3);
if (!dic.ContainsKey(grundy))
dic.Add(grundy, 1);
}
if (count >= 3 && count % 3 == 1)
{
int grundy = GetGrundy(count / 3) ^ GetGrundy(count / 3) ^ GetGrundy(count / 3 + 1);
if (!dic.ContainsKey(grundy))
dic.Add(grundy, 1);
}
if (count >= 3 && count % 3 == 2)
{
int grundy = GetGrundy(count / 3) ^ GetGrundy(count / 3 + 1) ^ GetGrundy(count / 3 + 1);
if (!dic.ContainsKey(grundy))
dic.Add(grundy, 1);
}
int ret = 0;
while (true)
{
if(!dic.ContainsKey(ret))
break;
ret++;
}
memo[count] = ret;
return ret;
}
static void Main()
{
int N = int.Parse(Console.ReadLine());
memo = new int[N + 1];
for (int i = 0; i <= N; i++)
memo[i] = -1;
if (GetGrundy(N) != 0)
Console.WriteLine("A");
else
Console.WriteLine("B");
}
}