結果

問題 No.1231 Make a Multiple of Ten
ユーザー keymoonkeymoon
提出日時 2021-01-18 12:25:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 4,153 ms
コンパイル使用メモリ 105,408 KB
実行使用メモリ 50,552 KB
最終ジャッジ日時 2023-08-20 19:44:00
合計ジャッジ時間 5,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
24,072 KB
testcase_01 AC 68 ms
19,716 KB
testcase_02 AC 70 ms
21,968 KB
testcase_03 AC 70 ms
21,944 KB
testcase_04 AC 122 ms
32,584 KB
testcase_05 AC 116 ms
30,420 KB
testcase_06 AC 93 ms
24,452 KB
testcase_07 AC 124 ms
34,640 KB
testcase_08 AC 97 ms
25,120 KB
testcase_09 AC 89 ms
23,216 KB
testcase_10 AC 120 ms
32,196 KB
testcase_11 AC 135 ms
41,272 KB
testcase_12 AC 184 ms
45,592 KB
testcase_13 AC 190 ms
50,552 KB
testcase_14 AC 72 ms
21,764 KB
testcase_15 AC 191 ms
46,700 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        int[][] steps = Enumerable.Repeat(0, 10).Select(_ => Enumerable.Repeat(int.MaxValue / 2, 10).ToArray()).ToArray();
        foreach (var group in a.GroupBy(x => x % 10))
        {
            var key = group.Key;
            var count = group.Count();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j <= Min(10, count); j++)
                {
                    var nxt = (i + j * key) % 10;
                    steps[i][nxt] = Min(steps[i][nxt], j);
                }
            }
        }
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++)
                for (int k = 0; k < 10; k++)
                    steps[j][k] = Min(steps[j][k], steps[j][i] + steps[i][k]);
        Console.WriteLine(n - steps[0][a.Sum() % 10]);
    }
}
0