結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-06-07 18:15:16 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| コンパイル時間 | 460 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-10-08 17:32:42 |
| 合計ジャッジ時間 | 2,040 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 5 |
ソースコード
#!/usr/bin/env python3
import math
N = int(input())
C = input().split()
ops = {'+' : 0, '-' : 0}
op = 0
nums = [0] * 10
for c in C:
if c in ops:
ops[c] += 1
op += 1
else :
nums[int(c)] += 1
num = N - op
nums_copy = list(nums)
numbers = [0] * (op + 1)
pos = 0
for i in range(op):
while nums[pos] == 0 :
pos += 1
numbers[i] = pos
nums[pos] -= 1
# 最大
a = 1
while True:
while pos < 10 and nums[pos] == 0 :
pos += 1
if pos >= 10 :
break
numbers[-1] += pos * a
nums[pos] -= 1
a *= 10
numbers.reverse()
#print(numbers)
max_ans = sum(numbers[:(ops['+'] + 1)]) - sum(numbers[(ops['+'] + 1):])
min_ans = - sum(numbers[:ops['-']]) + sum(numbers[(ops['-']):])
if ops['-'] == 0:
numbers = [0] * (op + 1)
pos = 0
nums_copy.reverse()
for i in range(op):
while nums_copy[pos] == 0 :
pos += 1
numbers[i] = 9 - pos
nums_copy[pos] -= 1
a = 1
while True:
while pos < 10 and nums_copy[pos] == 0 :
pos += 1
if pos >= 10 :
break
numbers[-1] += (9 - pos) * a
nums_copy[pos] -= 1
a *= 10
min_ans = - sum(numbers[:ops['-']]) + sum(numbers[(ops['-']):])
print(max_ans, min_ans)
cormoran