結果
| 問題 |
No.176 2種類の切手
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-09-05 18:46:52 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,773 bytes |
| コンパイル時間 | 2,672 ms |
| コンパイル使用メモリ | 113,872 KB |
| 実行使用メモリ | 663,868 KB |
| 最終ジャッジ日時 | 2024-10-08 03:33:13 |
| 合計ジャッジ時間 | 7,245 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 MLE * 2 |
コンパイルメッセージ
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();
int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
int A = wkArr[0];
int B = wkArr[1];
int T = wkArr[2];
if (T % A == 0 || T % B == 0) {
Console.WriteLine(T);
return;
}
int MinSumVal = int.MaxValue;
//Xを固定してYを求める
var ModBSet = new HashSet<int>();
for (int X = 0; A * X <= T; X++) {
int SumVal = A * X;
int RestVal = T - SumVal;
int ModB = RestVal % B;
if (ModB == 0) {
Console.WriteLine(T);
return;
}
//同じModが出たらBreak
if (ModBSet.Add(ModB) == false) break;
SumVal = T + (B - ModB);
if (MinSumVal > SumVal) MinSumVal = SumVal;
}
//Yを固定してXを求める
var ModASet = new HashSet<int>();
for (int Y = 0; B * Y <= T; Y++) {
int SumVal = B * Y;
int RestVal = T - SumVal;
int ModA = RestVal % A;
if (ModA == 0) {
Console.WriteLine(T);
return;
}
//同じModが出たらBreak
if (ModASet.Add(ModA) == false) break;
SumVal = T + (A - ModA);
if (MinSumVal > SumVal) MinSumVal = SumVal;
}
Console.WriteLine(MinSumVal);
}
}
明智重蔵