結果

問題 No.1097 Remainder Operation
ユーザー Yusei KatoYusei Kato
提出日時 2020-06-29 08:32:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 58,296 KB
実行使用メモリ 33,536 KB
最終ジャッジ日時 2023-09-25 06:15:05
合計ジャッジ時間 12,450 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
16,736 KB
testcase_01 AC 64 ms
16,604 KB
testcase_02 AC 68 ms
16,664 KB
testcase_03 AC 66 ms
16,800 KB
testcase_04 AC 66 ms
16,612 KB
testcase_05 AC 65 ms
16,848 KB
testcase_06 AC 66 ms
16,680 KB
testcase_07 AC 121 ms
18,848 KB
testcase_08 AC 121 ms
18,860 KB
testcase_09 AC 123 ms
19,044 KB
testcase_10 AC 121 ms
18,948 KB
testcase_11 AC 119 ms
18,852 KB
testcase_12 AC 549 ms
30,152 KB
testcase_13 AC 555 ms
30,216 KB
testcase_14 AC 551 ms
30,164 KB
testcase_15 AC 552 ms
30,376 KB
testcase_16 AC 547 ms
30,140 KB
testcase_17 AC 547 ms
30,788 KB
testcase_18 AC 545 ms
33,444 KB
testcase_19 AC 549 ms
33,536 KB
testcase_20 AC 555 ms
33,500 KB
testcase_21 AC 556 ms
33,496 KB
testcase_22 AC 561 ms
33,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();

    }
}
0