結果

問題 No.2693 Sword
ユーザー VvyLwVvyLw
提出日時 2024-03-23 15:51:33
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 127,624 KB
実行使用メモリ 10,760 KB
最終ジャッジ日時 2024-03-23 15:51:37
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 9 ms
8,056 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 5 ms
7,288 KB
testcase_16 AC 7 ms
10,760 KB
testcase_17 AC 5 ms
10,760 KB
testcase_18 AC 4 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 9 ms
8,568 KB
testcase_21 AC 12 ms
10,760 KB
testcase_22 AC 7 ms
7,160 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 6 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio: readf, writeln;
import core.stdc.stdlib: exit;
import core.checkedint: adds, muls;

bool chk(const long x){ return x > cast(long)1e18 || x < 0; }
void chmax(T, U)(ref T a, const U b) {
    if(a < b) {
		a = b;
	}
}
void main() {
    int n, k;
    long p;
    readf("%d %d %d\n", &n, &p, &k);
	auto dp = new long[][](n + 1, n + 1);
    dp[0][0] = p;
    foreach(i; 0..n) {
		int t, b;
		readf("%d %d\n", &t, &b);
		bool overflow;
        foreach(j; 0..n) {
            if(t == 1) {
                const x = adds(dp[i][j], b, overflow);
				if(overflow || chk(x)) {
					writeln(-1);
					exit(0);
				}
				chmax(dp[i + 1][j + 1], x);
			} else {
				const x = muls(dp[i][j], 2, overflow);
				if(overflow || chk(x)) {
					writeln(-1);
					exit(0);
				}
				chmax(dp[i + 1][j + 1], x);
			}
			chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    writeln(dp[n][k]);
}
0