結果

問題 No.2519 Coins in Array
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-27 22:31:27
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,116 bytes
コンパイル時間 9,721 ms
コンパイル使用メモリ 156,620 KB
実行使用メモリ 199,524 KB
最終ジャッジ日時 2023-10-27 22:31:43
合計ジャッジ時間 14,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
32,428 KB
testcase_01 AC 64 ms
32,424 KB
testcase_02 AC 63 ms
32,436 KB
testcase_03 AC 63 ms
32,404 KB
testcase_04 AC 63 ms
32,424 KB
testcase_05 AC 67 ms
32,424 KB
testcase_06 AC 64 ms
32,404 KB
testcase_07 AC 66 ms
32,404 KB
testcase_08 AC 66 ms
32,404 KB
testcase_09 AC 64 ms
32,404 KB
testcase_10 AC 76 ms
32,404 KB
testcase_11 AC 63 ms
32,424 KB
testcase_12 AC 62 ms
32,424 KB
testcase_13 AC 63 ms
32,424 KB
testcase_14 AC 64 ms
32,424 KB
testcase_15 AC 64 ms
32,436 KB
testcase_16 AC 63 ms
32,424 KB
testcase_17 AC 63 ms
32,424 KB
testcase_18 AC 65 ms
32,424 KB
testcase_19 AC 66 ms
32,436 KB
testcase_20 AC 64 ms
32,440 KB
testcase_21 AC 63 ms
32,436 KB
testcase_22 AC 62 ms
32,404 KB
testcase_23 AC 137 ms
59,444 KB
testcase_24 WA -
testcase_25 AC 65 ms
32,444 KB
testcase_26 AC 66 ms
32,444 KB
testcase_27 AC 117 ms
59,452 KB
testcase_28 AC 120 ms
59,452 KB
testcase_29 WA -
testcase_30 AC 117 ms
56,148 KB
testcase_31 AC 77 ms
37,144 KB
testcase_32 AC 98 ms
48,288 KB
testcase_33 AC 107 ms
50,984 KB
testcase_34 AC 89 ms
41,892 KB
testcase_35 WA -
testcase_36 AC 84 ms
40,144 KB
testcase_37 WA -
testcase_38 AC 101 ms
49,620 KB
testcase_39 AC 85 ms
41,148 KB
testcase_40 AC 116 ms
199,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (119 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

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

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var (m, order) = Coins(n, a);
        WriteLine(m);
        WriteLine(order);
    }
    static (long m, string order) Coins(int n, int[] a)
    {
        if (n == 2)
        {
            return (Coin(a[0], a[1]), "1 2");
        }
        if (n == 3)
        {
            var min = long.MaxValue;
            var minorder = "";
            {
                var m = Coin(Coin(a[0], a[1]), a[2]);
                if (min > m)
                {
                    min = m;
                    minorder = "1 2\n1 2";
                }
            }
            {
                var m = Coin(Coin(a[0], a[2]), a[1]);
                if (min > m)
                {
                    min = m;
                    minorder = "1 3\n1 2";
                }
            }
            {
                var m = Coin(Coin(a[1], a[2]), a[0]);
                if (min > m)
                {
                    min = m;
                    minorder = "2 3\n1 2";
                }
            }
            return (min, minorder);
        }
        var order = new System.Text.StringBuilder();
        order.Append("1 2\n1 2");
        for (var i = n - 2; i >= 2; --i)
        {
            order.Append($"\n1 {i}");
        }
        return (0, order.ToString());
    }
    static long Coin(long a, long b)
    {
        if (a == 0 || b == 0) return 0;
        if (GCD(a, b) > 1) return 0;
        return (a - 1) * (b - 1);
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
}
0