結果
| 問題 |
No.1595 The Final Digit
|
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2025-02-20 21:15:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,754 bytes |
| コンパイル時間 | 3,383 ms |
| コンパイル使用メモリ | 112,568 KB |
| 実行使用メモリ | 31,300 KB |
| 最終ジャッジ日時 | 2025-02-20 21:15:07 |
| 合計ジャッジ時間 | 3,432 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 1 RE * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/1595
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("11 11 11 7");
//7
}
else if (InputPattern == "Input2") {
WillReturn.Add("86 91 20 1001");
//8
}
else if (InputPattern == "Input3") {
WillReturn.Add("31415 92653 58979 1000000000000000000");
//5
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long A1 = wkArr[0];
long A2 = wkArr[1];
long A3 = wkArr[2];
long K = wkArr[3];
var AppearList = new List<string>();
var AppearSet = new HashSet<string>();
string[] PreCycleArr;
string[] CycleArr;
K -= 3;
var CurrList = new List<long>() { A1, A2, A3 };
while (true) {
string CurrHash = GetHash(CurrList);
if (AppearSet.Contains(CurrHash)) {
PreCycleArr = AppearList.TakeWhile(pX => pX != CurrHash).ToArray();
CycleArr = AppearList.SkipWhile(pX => pX != CurrHash).ToArray();
break;
}
AppearList.Add(CurrHash);
AppearSet.Add(CurrHash);
DeriveNextList(CurrList);
}
if (K <= PreCycleArr.Length) {
string PrevHash1 = PreCycleArr[K - 1];
Console.WriteLine(DeriveResult(PrevHash1));
}
long RestK = K - PreCycleArr.Length;
string PrevHash2 = CycleArr[(RestK - 1) % CycleArr.Length];
Console.WriteLine(DeriveResult(PrevHash2));
}
static long DeriveResult(string pHash)
{
long Result = 0;
string[] SplitArr = pHash.Split(',');
foreach (string EachStr in SplitArr) {
Result += long.Parse(EachStr);
Result %= 10;
}
return Result;
}
// 現在の値のListを引数として、次をList設定
static void DeriveNextList(List<long> pList)
{
long SumVal = pList.Sum() % 10;
pList.Add(SumVal);
pList.RemoveAt(0);
}
// 現在の3つの値からハッシュ値を求める
static string GetHash(List<long> pList)
{
return string.Format("{0},{1},{2}", pList[0], pList[1], pList[2]);
}
}
aketijyuuzou