結果
問題 | No.10 +か×か |
ユーザー | しらっ亭 |
提出日時 | 2015-06-23 00:03:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,811 ms / 5,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 10,904 KB |
実行使用メモリ | 336,520 KB |
最終ジャッジ日時 | 2023-08-21 06:13:10 |
合計ジャッジ時間 | 7,590 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,128 KB |
testcase_01 | AC | 16 ms
8,012 KB |
testcase_02 | AC | 16 ms
8,040 KB |
testcase_03 | AC | 2,744 ms
332,936 KB |
testcase_04 | AC | 34 ms
10,660 KB |
testcase_05 | AC | 16 ms
7,972 KB |
testcase_06 | AC | 2,811 ms
336,520 KB |
testcase_07 | AC | 895 ms
135,240 KB |
testcase_08 | AC | 118 ms
24,516 KB |
testcase_09 | AC | 64 ms
16,864 KB |
testcase_10 | AC | 16 ms
7,968 KB |
testcase_11 | AC | 16 ms
8,052 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 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()