結果
問題 | No.1231 Make a Multiple of Ten |
ユーザー |
![]() |
提出日時 | 2021-01-18 12:25:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 1,257 bytes |
コンパイル時間 | 1,057 ms |
コンパイル使用メモリ | 114,700 KB |
実行使用メモリ | 52,136 KB |
最終ジャッジ日時 | 2024-12-14 01:29:23 |
合計ジャッジ時間 | 3,081 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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]); } }