提出 #49720390


ソースコード 拡げる

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

public class C
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var N = Scanner.Scan<int>();
        var Q = Scanner.ScanEnumerable<int>().ToArray();
        var A = Scanner.ScanEnumerable<int>().ToArray();
        var B = Scanner.ScanEnumerable<int>().ToArray();
        const long Inf = 1L << 60;
        var maxA = Inf;

        for (var i = 0; i < N; i++)
        {
            maxA = Math.Min(maxA, A[i] == 0 ? Inf : (Q[i] / A[i]));
        }

        long answer = 0;
        for (var a = 0; a <= maxA; a++)
        {
            var b = Inf;
            for (var i = 0; i < N; i++)
            {
                var r = Q[i] - a * A[i];
                var maxB = B[i] == 0 ? Inf : (r / B[i]);
                b = Math.Min(b, maxB);
            }

            answer = Math.Max(answer, a + b);
        }

        Console.WriteLine(answer);
    }


    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

提出情報

提出日時
問題 C - Leftover Recipes
ユーザ AconCavy
言語 C# 11.0 (.NET 7.0.7)
得点 300
コード長 3584 Byte
結果 AC
実行時間 57 ms
メモリ 26616 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 4
AC × 18
セット名 テストケース
Sample 01-sample.txt, 02-sample.txt, 03-sample.txt, 04-sample.txt
All 01-sample.txt, 02-sample.txt, 03-sample.txt, 04-sample.txt, 05-hidden.txt, 06-hidden.txt, 07-hidden.txt, 08-hidden.txt, 09-hidden.txt, 10-hidden.txt, 11-hidden.txt, 12-hidden.txt, 13-hidden.txt, 14-hidden.txt, 15-hidden.txt, 16-hidden.txt, 17-hidden.txt, 18-hidden.txt
ケース名 結果 実行時間 メモリ
01-sample.txt AC 52 ms 26204 KiB
02-sample.txt AC 53 ms 26244 KiB
03-sample.txt AC 52 ms 26136 KiB
04-sample.txt AC 53 ms 26148 KiB
05-hidden.txt AC 41 ms 26140 KiB
06-hidden.txt AC 47 ms 26460 KiB
07-hidden.txt AC 46 ms 26584 KiB
08-hidden.txt AC 48 ms 26444 KiB
09-hidden.txt AC 57 ms 26268 KiB
10-hidden.txt AC 49 ms 26224 KiB
11-hidden.txt AC 49 ms 26120 KiB
12-hidden.txt AC 50 ms 26148 KiB
13-hidden.txt AC 45 ms 26276 KiB
14-hidden.txt AC 46 ms 26156 KiB
15-hidden.txt AC 55 ms 26616 KiB
16-hidden.txt AC 46 ms 26320 KiB
17-hidden.txt AC 54 ms 26168 KiB
18-hidden.txt AC 46 ms 26612 KiB