結果

問題 No.2519 Coins in Array
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-27 22:37:29
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 6,589 ms
コンパイル使用メモリ 157,812 KB
実行使用メモリ 200,352 KB
最終ジャッジ日時 2023-10-27 22:37:46
合計ジャッジ時間 13,144 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
32,080 KB
testcase_01 AC 65 ms
32,076 KB
testcase_02 AC 64 ms
32,088 KB
testcase_03 AC 86 ms
32,056 KB
testcase_04 AC 64 ms
32,076 KB
testcase_05 AC 63 ms
32,076 KB
testcase_06 AC 64 ms
32,056 KB
testcase_07 AC 65 ms
32,056 KB
testcase_08 AC 64 ms
32,056 KB
testcase_09 AC 66 ms
32,056 KB
testcase_10 AC 64 ms
32,056 KB
testcase_11 AC 64 ms
32,076 KB
testcase_12 AC 63 ms
32,076 KB
testcase_13 AC 64 ms
32,076 KB
testcase_14 AC 65 ms
32,076 KB
testcase_15 AC 65 ms
32,088 KB
testcase_16 AC 67 ms
32,076 KB
testcase_17 AC 74 ms
32,076 KB
testcase_18 AC 64 ms
32,076 KB
testcase_19 AC 65 ms
32,088 KB
testcase_20 AC 65 ms
32,088 KB
testcase_21 AC 64 ms
32,088 KB
testcase_22 AC 65 ms
32,056 KB
testcase_23 AC 117 ms
59,096 KB
testcase_24 AC 119 ms
58,008 KB
testcase_25 AC 70 ms
32,096 KB
testcase_26 AC 72 ms
32,096 KB
testcase_27 AC 129 ms
59,092 KB
testcase_28 AC 119 ms
59,084 KB
testcase_29 AC 120 ms
59,084 KB
testcase_30 AC 116 ms
55,780 KB
testcase_31 AC 78 ms
36,772 KB
testcase_32 AC 123 ms
47,928 KB
testcase_33 AC 106 ms
50,624 KB
testcase_34 AC 91 ms
41,532 KB
testcase_35 AC 107 ms
50,928 KB
testcase_36 AC 82 ms
39,784 KB
testcase_37 AC 78 ms
35,800 KB
testcase_38 AC 102 ms
49,260 KB
testcase_39 AC 92 ms
40,788 KB
testcase_40 AC 113 ms
200,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (82 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\n{n-3} {n-2}");
        for (var i = n - 3; i >= 2; --i)
        {
            order.Append($"\n1 {i}");
        }
        return (0, order.ToString());
    }
    static long Coin(long a, long b)
    {
        checked {
            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