結果

問題 No.3681 心の沸騰石
コンテスト
ユーザー aketijyuuzou
提出日時 2026-09-05 14:17:51
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
AC  
実行時間 19 ms / 2,000 ms
+ 99µs
コード長 3,224 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,546 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2026-09-05 14:18:26
合計ジャッジ時間 3,342 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("800 200 100");
            WillReturn.Add("1 2 2 1");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("800 1200 1200");
            WillReturn.Add("300 300 300 300");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("800 800 800");
            WillReturn.Add("1 1 1 0");
            //1
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("314159265 9 26");
            WillReturn.Add("17781089 21082123 14498465 7071840");
            //18908650
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static long[] GetSplitArr(string pStr)
    {
        return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray();
    }

    static long mR;
    static long mP;
    static long mQ;

    static long mRedCnt;
    static long mYeloowCnt;
    static long mBlueCnt;
    static long mGreenCnt;

    static void Main()
    {
        List<string> InputList = GetInputList();
        long[] wkArr = GetSplitArr(InputList[0]);
        mR = wkArr[0];
        mP = wkArr[1];
        mQ = wkArr[2];

        wkArr = GetSplitArr(InputList[1]);
        mRedCnt = wkArr[0];
        mYeloowCnt = wkArr[1];
        mBlueCnt = wkArr[2];
        mGreenCnt = wkArr[3];

        long L = 0;
        long R = (mRedCnt + mYeloowCnt + mBlueCnt + mGreenCnt)+100;

        //bool Res = CanAchieve(2);
        //Console.WriteLine(Res);
        //return;

        while (L + 1 < R) {
            long Mid = (L + R) / 2;
            bool Result = CanAchieve(Mid);
            //Console.WriteLine("CanAchieve({0})={1}", Mid, Result);

            if (Result) {
                L = Mid;
            }
            else {
                R = Mid;
            }
        }
        Console.WriteLine(L);

    }

    // X人のルーマニア人を作れるかを返す
    static bool CanAchieve(long pX)
    {
        if (pX == 0) return true;

        long RestRate = mR - mP * pX;
        if (RestRate < 0) return false;

        long RestChangeCnt = RestRate / mQ;

        // 交換要因
        long ChangeMan = mGreenCnt;
        if (mRedCnt > pX) ChangeMan += mRedCnt - pX;
        if (mYeloowCnt > pX) ChangeMan += mYeloowCnt - pX;
        if (mBlueCnt > pX) ChangeMan += mBlueCnt - pX;

        if (mRedCnt < pX) {
            RestChangeCnt -= pX - mRedCnt;
            ChangeMan -= pX - mRedCnt;
        }
        if (mYeloowCnt < pX) {
            RestChangeCnt -= pX - mYeloowCnt;
            ChangeMan -= pX - mYeloowCnt;
        }
        if (mBlueCnt < pX) {
            RestChangeCnt -= pX - mBlueCnt;
            ChangeMan -= pX - mBlueCnt;
        }

        if (RestChangeCnt < 0) return false;
        if (ChangeMan < 0) return false;
        return true;
    }
}
0