結果

問題 No.443 GCD of Permutation
ユーザー eitahoeitaho
提出日時 2016-12-07 21:22:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 1,000 ms
コード長 2,679 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 109,568 KB
実行使用メモリ 24,204 KB
最終ジャッジ日時 2023-08-04 03:01:31
合計ジャッジ時間 5,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,888 KB
testcase_01 AC 62 ms
23,720 KB
testcase_02 AC 65 ms
21,888 KB
testcase_03 AC 65 ms
21,876 KB
testcase_04 AC 65 ms
21,836 KB
testcase_05 AC 60 ms
21,760 KB
testcase_06 AC 68 ms
21,828 KB
testcase_07 AC 68 ms
21,840 KB
testcase_08 AC 69 ms
19,872 KB
testcase_09 AC 67 ms
23,816 KB
testcase_10 AC 65 ms
23,864 KB
testcase_11 AC 66 ms
21,856 KB
testcase_12 AC 67 ms
23,912 KB
testcase_13 AC 65 ms
21,808 KB
testcase_14 AC 62 ms
21,836 KB
testcase_15 AC 68 ms
23,880 KB
testcase_16 AC 67 ms
21,856 KB
testcase_17 AC 66 ms
23,844 KB
testcase_18 AC 68 ms
22,128 KB
testcase_19 AC 68 ms
21,744 KB
testcase_20 AC 71 ms
19,876 KB
testcase_21 AC 69 ms
21,728 KB
testcase_22 AC 66 ms
23,860 KB
testcase_23 AC 65 ms
21,824 KB
testcase_24 AC 65 ms
21,792 KB
testcase_25 AC 70 ms
21,956 KB
testcase_26 AC 68 ms
21,988 KB
testcase_27 AC 69 ms
23,884 KB
testcase_28 AC 66 ms
24,072 KB
testcase_29 AC 68 ms
22,028 KB
testcase_30 AC 66 ms
22,052 KB
testcase_31 AC 67 ms
24,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        var S = Reader.String();
        var A = S.Select(c => c - '0').ToArray();
        var D = A.Distinct().OrderBy(a => a).ToArray();
        if (D.Length == 1) { Console.WriteLine(S); return; }

        int gcd = 0;
        foreach (int a in D)
            foreach (int b in D)
                gcd = GCD(gcd, 9 * Math.Abs(a - b));
        int r = 0;
        foreach (int a in A.Reverse<int>())
            r = (r * 10 + a) % gcd;
        gcd = GCD(gcd, r);

        Console.WriteLine(gcd);
    }

    static int GCD(int a, int b)
    {
        while (b != 0) { int r = a % b; a = b; b = r; }
        return a;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0