結果
| 問題 |
No.176 2種類の切手
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-09-05 16:54:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,317 bytes |
| コンパイル時間 | 915 ms |
| コンパイル使用メモリ | 113,472 KB |
| 実行使用メモリ | 31,820 KB |
| 最終ジャッジ日時 | 2024-10-08 03:32:59 |
| 合計ジャッジ時間 | 4,369 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 1 -- * 9 |
コンパイルメッセージ
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.Generic;
using System.Linq;
class Program
{
static string InputPattern = "Input4";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("50 80 120");
//130
//50円切手と80円切手を組み合わせて、ちょうど120円にすることはできません。
//この場合、50円切手と80円切手を1枚ずつ使って130円にするのが、
//120円以上での最少額になります。
}
else if (InputPattern == "Input2") {
WillReturn.Add("123 456 1");
//123
//必ずしも両方の種類の切手を使う必要はありません。
//この場合、額面の小さい123円の切手を1枚貼ることになります。
}
else if (InputPattern == "Input3") {
WillReturn.Add("1234 1688 10000");
//10000
//うまくすれば、ちょうど10000円にできるようです。
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray();
long wkA = wkArr[0];
long wkB = wkArr[1];
long T = wkArr[2];
//A<Bとする
long A = Math.Min(wkA, wkB);
long B = Math.Max(wkA, wkB);
if (T % A == 0 || T % B == 0) {
Console.WriteLine(T);
return;
}
//Bを固定してAを求める
long MinSumVal = long.MaxValue;
for (long I = 0; ; I++) {
long SumVal = B * I;
long RestVal = T - SumVal;
if (RestVal > 0) {
long Syou = RestVal / A;
if (RestVal % A > 0) Syou++;
SumVal += A * Syou;
if (MinSumVal > SumVal) MinSumVal = SumVal;
}
else {
if (MinSumVal > SumVal) MinSumVal = SumVal;
break;
}
}
Console.WriteLine(MinSumVal);
}
}
明智重蔵