結果

問題 No.176 2種類の切手
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-05 18:46:52
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 2,773 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 108,160 KB
実行使用メモリ 1,174,008 KB
最終ジャッジ日時 2024-04-16 22:16:56
合計ジャッジ時間 5,279 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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);
    }
}
0