結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー bluemeganebluemegane
提出日時 2021-06-12 07:05:38
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,370 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 68,148 KB
実行使用メモリ 44,440 KB
最終ジャッジ日時 2023-08-22 03:11:10
合計ジャッジ時間 5,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
44,440 KB
testcase_01 AC 63 ms
23,348 KB
testcase_02 AC 63 ms
21,308 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int aa { get; set; }
    public int bb { get; set; }
}

public class Hello
{
    public static int n, m;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(line[0]);
        m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var ps = new List<P>();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (a[i] == b[j]) ps.Add(new P { aa = i, bb = j });
        getAns(ps);
    }
    static void getAns(List<P> ps)
    {
        var ans = int.MaxValue;
        if (ps.Count() == 0) { Console.WriteLine(-1); return; }
        var tmax = Max(n, m);
        foreach (var x in ps)
        {
            for (int L = 0; L <= tmax; L++)
                for (int k = 0; k <= tmax; k++)
                {
                    if ((m * L + x.bb - x.aa) % n == 0)
                    {
                        var p = m * L + x.bb;
                        ans = Min(ans, p);
                    }
                }
        }
        Console.WriteLine(ans + 1);
    }
}
0