結果
問題 |
No.297 カードの数式
|
ユーザー |
![]() |
提出日時 | 2015-11-07 23:03:58 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,248 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 14:05:29 |
合計ジャッジ時間 | 1,310 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 1 RE * 8 |
ソースコード
#!/usr/bin/python # -*- coding: utf-8 -*- N = input() inputs = raw_input().split() numbers = [] symbols = [] for n in inputs: if n.isdigit(): numbers.append(n) else: symbols.append(n) numbers = map(int, numbers) s_numbers = sorted(numbers, reverse=True) # [5,4,3,2,1] smalls = [] for loop in xrange(len(symbols)): smalls.append(s_numbers.pop()) #small numbers str_numbers = map(str, s_numbers) big = ''.join(str_numbers) big = int(big) #biggest number possible n_plus = symbols.count('+') n_minus = symbols.count('-') BIG = big big_smalls = smalls for n in xrange(n_plus): BIG += big_smalls.pop() for n in xrange(n_minus): BIG -= big_smalls.pop() if n_minus > 0: SMALL = 0 sma_smalls = smalls sma_smalls.append(BIG) for n in xrange(n_minus): SMALL -= sma_smalls.pop() for n in xrange(n_plus): SMALL += sma_smalls.pop() elif n_minus == 0: #ここから解説見た smalls = [[] for loop in xrange(n_plus+1)] for i in xrange(len(numbers)): smalls[i%len(smalls)].append(numbers[i]) smalls = map(sorted, smalls) SMALL = 0 for lst in smalls: lst = [str(n) for n in lst] n = int(''.join(lst)) SMALL += n print BIG, SMALL