結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー daut-dlangdaut-dlang
提出日時 2019-12-16 23:12:47
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 503 ms / 2,500 ms
コード長 2,549 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 111,816 KB
実行使用メモリ 58,136 KB
最終ジャッジ日時 2023-09-04 04:06:21
合計ジャッジ時間 6,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 160 ms
52,472 KB
testcase_12 AC 256 ms
52,680 KB
testcase_13 AC 162 ms
58,136 KB
testcase_14 AC 25 ms
10,320 KB
testcase_15 AC 171 ms
21,808 KB
testcase_16 AC 361 ms
54,112 KB
testcase_17 AC 48 ms
11,096 KB
testcase_18 AC 440 ms
56,948 KB
testcase_19 AC 151 ms
21,812 KB
testcase_20 AC 31 ms
9,844 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 220 ms
38,884 KB
testcase_25 AC 293 ms
56,352 KB
testcase_26 AC 362 ms
56,772 KB
testcase_27 AC 399 ms
53,912 KB
testcase_28 AC 503 ms
56,272 KB
testcase_29 AC 234 ms
53,680 KB
testcase_30 AC 57 ms
11,288 KB
testcase_31 AC 6 ms
8,212 KB
testcase_32 AC 378 ms
52,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

T binarySearch(alias pred, T)(T ok, T ng)
{ 
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng) / 2;
		if (unaryFun!pred(mid))
			ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto N = RD;
	auto A = RDA;
	auto B = RDA;
	auto D = RDA;
	D.sort!"a > b"();

	bool f(long x)
	{
		auto m = N - x;
		auto dp = new bool[][](x+1, x+1);
		dp[0][0] = true;
		foreach (i; 0..x)
		{
			bool ok;
			debug writeln(i, " ", dp[i]);
			foreach (j; 0..i+1)
			{
				if (dp[i][j] == false) continue;
				auto ab1 = A[j+1] + B[i-j];
				auto ab2 = A[j] + B[i-j+1];
				//debug writeln(ab1, ":", ab2);
				if (ab1 >= D[m+i])
				{
					dp[i+1][j+1] = true;
					ok = true;
				}
				if (ab2 >= D[m+i])
				{
					dp[i+1][j] = true;
					ok = true;
				}
			}
			if (!ok)
				return false;
		}
		return true;
	}

	auto ans = binarySearch!(f)(0, N+1);

	writeln(ans);
	stdout.flush;
	debug readln;
}
0