結果

問題 No.27 板の準備
ユーザー iicafiaxusiicafiaxus
提出日時 2018-12-10 22:29:18
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 113,508 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 21:32:07
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 3 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int v1 = read.to!int;
	int v2 = read.to!int;
	int v3 = read.to!int;
	int v4 = read.to!int;
	
	int ans = 10000;
	foreach(a; 1 .. 29) foreach(b; a + 1 .. 30) foreach(c; b + 1 .. 31){
		int tmp = solve(v1, a, b, c) + solve(v2, a, b, c) + solve(v3, a, b, c) + solve(v4, a, b, c);
		if(tmp < ans) ans = tmp;
	}
	
	ans.writeln;
}

int solve(int v, int a, int b, int c){
	int res = 10000;
	foreach(i; 0 .. v) foreach(j; 0 .. v){
		if(i * a + j * b > v) break;
		if((v - i * a - j * b) % c > 0) continue;
		int tmp = i + j + (v - i * a - j * b) / c;
		if(tmp < res) res = tmp;
	}
	return res;
}
0