結果
問題 | No.10 +か×か |
ユーザー | しらっ亭 |
提出日時 | 2015-06-23 00:24:57 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 498 ms / 5,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 10,892 KB |
実行使用メモリ | 83,052 KB |
最終ジャッジ日時 | 2023-08-21 06:12:52 |
合計ジャッジ時間 | 2,120 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,748 KB |
testcase_01 | AC | 16 ms
7,900 KB |
testcase_02 | AC | 15 ms
7,812 KB |
testcase_03 | AC | 302 ms
50,032 KB |
testcase_04 | AC | 26 ms
10,084 KB |
testcase_05 | AC | 16 ms
7,776 KB |
testcase_06 | AC | 498 ms
83,052 KB |
testcase_07 | AC | 319 ms
45,868 KB |
testcase_08 | AC | 38 ms
12,320 KB |
testcase_09 | AC | 54 ms
16,264 KB |
testcase_10 | AC | 16 ms
7,756 KB |
testcase_11 | AC | 16 ms
7,756 KB |
ソースコード
def solve(N, T, A): memo = {} def able(i, j): if (i, j) in memo: return memo[i, j] memo[i, j] = False if i == N: if j == T: memo[i, j] = True else: if j + A[i] <= T and able(i + 1, j + A[i]): memo[i, j] = True return memo[i, j] if j * A[i] <= T and able(i + 1, j * A[i]): memo[i, j] = True return memo[i, j] ans = [] j = A[0] for i in range(1, N): if j + A[i] <= T and able(i + 1, j + A[i]): ans.append('+') j += A[i] continue if j * A[i] <= T and able(i + 1, j * A[i]): ans.append('*') j *= A[i] continue return ''.join(ans) def main(): n = int(input()) total = int(input()) a = list(map(int, input().split())) print(solve(n, total, a)) if __name__ == '__main__': main()