結果
| 問題 | 
                            No.1097 Remainder Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Yusei Kato
                         | 
                    
| 提出日時 | 2020-06-29 08:32:12 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 551 ms / 2,000 ms | 
| コード長 | 1,989 bytes | 
| コンパイル時間 | 869 ms | 
| コンパイル使用メモリ | 107,648 KB | 
| 実行使用メモリ | 37,376 KB | 
| 最終ジャッジ日時 | 2024-07-18 05:16:39 | 
| 合計ジャッジ時間 | 10,453 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 | 
コンパイルメッセージ
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;
namespace Problem1097
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = GetInt();
            var A = GetIntArray();
            int Q = GetInt();
            var K = new long[Q];
            for(int i = 0; i < Q; i++)
            {
                K[i] = GetLong();
            }
            int j = 1;
            var X = new List<long> { 0 };
            var XHash = new HashSet<long> { 0 };
            int cycle = 0;
            int ba = 0;
            long measure = 0;
            while(true)
            {
                int r = (int)X[j - 1] % N;
                long temp = X[j - 1] + A[r];
                long tempmod = temp % N;
                if(XHash.Contains(tempmod))
                {
                    ba = X.FindIndex(x => x % N == tempmod);
                    cycle = j - ba;
                    measure = (int)(temp - X[ba]);
                    break;
                }
                else
                {
                    X.Add(temp);
                    XHash.Add(tempmod);
                    j++;
                }
            }
            for(int i = 0; i < Q; i++)
            {
                long laps = Math.Max((K[i] - ba) / cycle, 0);
                int index = ba + (int)((K[i] - ba) % cycle);
                Console.WriteLine(X[index] + laps * measure);
            }
        }
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
}
            
            
            
        
            
Yusei Kato