結果
問題 | No.10 +か×か |
ユーザー | しらっ亭 |
提出日時 | 2015-06-23 00:03:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,866 ms / 5,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 339,016 KB |
最終ジャッジ日時 | 2024-05-08 11:46:05 |
合計ジャッジ時間 | 7,829 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,752 KB |
testcase_01 | AC | 26 ms
10,752 KB |
testcase_02 | AC | 30 ms
10,752 KB |
testcase_03 | AC | 2,795 ms
335,544 KB |
testcase_04 | AC | 44 ms
13,384 KB |
testcase_05 | AC | 27 ms
10,752 KB |
testcase_06 | AC | 2,866 ms
339,016 KB |
testcase_07 | AC | 903 ms
137,828 KB |
testcase_08 | AC | 132 ms
27,220 KB |
testcase_09 | AC | 77 ms
19,656 KB |
testcase_10 | AC | 27 ms
10,880 KB |
testcase_11 | AC | 31 ms
10,880 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()