結果
| 問題 | No.636 硬貨の枚数2 |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-10-29 18:16:26 |
| 言語 | C# (.NET 10.0.403 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 35 ms / 2,000 ms |
| + 134µs | |
| コード長 | 1,444 bytes |
| 記録 | |
| コンパイル時間 | 8,510 ms |
| コンパイル使用メモリ | 170,076 KB |
| 実行使用メモリ | 29,964 KB |
| 最終ジャッジ日時 | 2026-10-29 18:16:50 |
| 合計ジャッジ時間 | 14,213 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge7_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 65 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (191 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
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 char[][] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine().ToCharArray()).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var n = ReadLine();
var list = new int[n.Length * 2];
for (var i = 0; i < n.Length; ++i)
{
list[i * 2] = (n[i] - '0') / 5;
list[i * 2 + 1] = (n[i] - '0') % 5;
}
var dp0 = 0;
var dp1 = 0;
var INF = int.MaxValue / 2;
if (list[0] == 0) dp1 = INF;
else
{
dp0 = 1;
dp1 = 2;
}
for (var i = 1; i < list.Length; ++i)
{
var ndp0 = 0;
var ndp1 = 0;
if (i % 2 == 0)
{
ndp0 = Math.Min(dp0, dp1) + list[i];
ndp1 = Math.Min(dp0, dp1 - 2) + 3 - list[i];
}
else
{
ndp0 = Math.Min(dp0, dp1) + list[i];
ndp1 = Math.Min(dp0, dp1 - 2) + 6 - list[i];
}
dp0 = ndp0;
dp1 = ndp1;
}
WriteLine(Math.Min(dp0, dp1));
}
}