AtCoder Beginner Contest 054

Submission #1588149

Source codeソースコード

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int N, Ma, Mb;
    int[] a, b, c;
    const int INF = 1234567890;
    void Solve() {
        //intput
        N = io.Int;
        Ma = io.Int;
        Mb = io.Int;
        a = new int[N];
        b = new int[N];
        c = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = io.Int;
            b[i] = io.Int;
            c[i] = io.Int;
        }
        //cal
        var dp = new int[50, 500, 500];
        for (int i = 0; i < dp.GetLength(0); ++i)
            for (int j = 0; j < dp.GetLength(1); ++j)
                for (int k = 0; k < dp.GetLength(2); ++k)
                    dp[i, j, k] = INF;
        dp[0, 0, 0] = 0;
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < (N+1)*10+1; ++j)
                for (int k = 0; k < (N+1)*10+1; ++k) {
                    if (dp[i, j, k] == INF) continue;
                    //加える
                    dp[i + 1, j + a[i], k + b[i]] =
                        Math.Min(dp[i + 1, j + a[i], k + b[i]], dp[i, j, k] + c[i]);
                    //加えない
                    dp[i + 1, j, k] = Math.Min(dp[i + 1, j, k], dp[i, j, k]);
                }
        int ans = INF;
        for (int j = 1; j < dp.GetLength(1); ++j)
            for (int k = 1; k < dp.GetLength(2); ++k)
                if (j * Mb == k * Ma)
                    ans = Math.Min(ans, dp[N, j, k]);
        //res
        Console.WriteLine(ans == INF ? -1 : ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Submission

Task問題 D - Mixing Experiment
User nameユーザ名 takt
Created time投稿日時
Language言語 C# (Mono 4.6.2.0)
Status状態 AC
Score得点 400
Source lengthソースコード長 2829 Byte
File nameファイル名
Exec time実行時間 247 ms
Memory usageメモリ使用量 59744 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 400 / 400 sample_01.txt,sample_02.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 188 ms 57696 KB
sample_02.txt AC 188 ms 59744 KB
subtask_1_01.txt AC 187 ms 59744 KB
subtask_1_02.txt AC 187 ms 59744 KB
subtask_1_03.txt AC 187 ms 57824 KB
subtask_1_04.txt AC 192 ms 57696 KB
subtask_1_05.txt AC 189 ms 57696 KB
subtask_1_06.txt AC 193 ms 57696 KB
subtask_1_07.txt AC 196 ms 59744 KB
subtask_1_08.txt AC 204 ms 59744 KB
subtask_1_09.txt AC 208 ms 59744 KB
subtask_1_10.txt AC 219 ms 59744 KB
subtask_1_11.txt AC 235 ms 57696 KB
subtask_1_12.txt AC 246 ms 59744 KB
subtask_1_13.txt AC 243 ms 57696 KB
subtask_1_14.txt AC 244 ms 59744 KB
subtask_1_15.txt AC 244 ms 57824 KB
subtask_1_16.txt AC 246 ms 59744 KB
subtask_1_17.txt AC 247 ms 59744 KB
subtask_1_18.txt AC 244 ms 57824 KB