import fractions
import time
import copy
import random
import sys
sys.setrecursionlimit(100000000)

class Node:
    def setVal(this, val):
        this.op = "value"
        this.result = val
        return this
    
    def read(this):
        if this.op == "value":
            return this.result
        leftVal = this.left.read()
        rightVal = this.right.read()
        if this.op == "concat":
            mul = 1
            tmp = rightVal
            while tmp > 0:
                mul *= 10
                tmp //= 10
            result = leftVal * mul + rightVal
        elif this.op == "+":
            result = leftVal + rightVal
        elif this.op == "-":
            result = leftVal - rightVal
        elif this.op == "/":
            result = leftVal / rightVal
        elif this.op == "*":
            result = leftVal * rightVal
        return result
    
    def setOp(this, leftNode, rightNode, typeOp):
        this.left = leftNode
        this.right = rightNode
        this.op = typeOp
        this.result = this.read()
        return this
    
    def getNodeList(this):
        if this.op == "value":
            return [this]
        else:
            return this.left.getNodeList() + [this] + this.right.getNodeList()
    
    def getString(this):
        if this.op == "value":
            return str(this.result)
        elif this.op == "concat":
            return "(" + this.left.getString() + " " + this.right.getString() + ")"
        else:
            return "(" + this.left.getString() + this.op + this.right.getString() +  ")"

ops = ["concat", "+", "-", "*", "/"]

n = int(input())
a = list(map(int, input().split()))
# 甘え(デバッグつらいので)
start_time = time.time()
node_vals = [Node().setVal(v) for v in a]
# 流石に超えんやろ
cur_val = float("inf")
cur_str = ""
top_main = None

while time.time() - start_time < 2:
    # 取り敢えず何か作ってみる?
    tmp_node_vals = copy.deepcopy(node_vals)
    # shuffle
    random.shuffle(tmp_node_vals)
    main = tmp_node_vals[0]
    # 前から適当に繋いでいく
    for i in range(1, n):
        if i == 1:
            use = random.randint(0, 4)
        else:
            use = random.randint(1, 4)
        main = Node().setOp(main, tmp_node_vals[i], ops[use])
    getVal = main.read()
    if abs(getVal-100) < abs(cur_val-100):
        # print(getVal, result)
        cur_val = getVal
        cur_str = main.getString()
        top_main = main

node_list = top_main.getNodeList()
while time.time() - start_time < 3:
    # どれかノードを選んで変えるだけ
    idx = random.randint(0, len(node_list) - 1)
    if node_list[i].op == "value":
        continue
    to = random.randint(1, 4)
    node_list[i].op = ops[to]
    new_val = top_main.read()
    if abs(cur_val-100) < abs(new_val-100):
        new_val = cur_val
        cur_str = top_main.getString()

print(cur_str)

Battle History

ConfigScoreDate
komachi baby10000000000002019/11/22 17:17:58
5 small10000000000002019/11/22 17:17:58
5 small10000000000002019/11/22 17:17:58
5 small10000000000002019/11/22 17:17:58
20 middle9999860703002019/11/22 17:17:58
20 middle9999304559002019/11/22 17:17:58
20 middle9999875504002019/11/22 17:17:58
1000 large9908358177002019/11/22 17:17:58
1000 large9976678225002019/11/22 17:17:58
1000 large9923204241002019/11/22 17:17:58