結果

問題 No.3024 等式
ユーザー zimphazimpha
提出日時 2017-03-31 23:55:13
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 1,383 ms / 5,000 ms
コード長 1,119 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 77,388 KB
実行使用メモリ 101,640 KB
最終ジャッジ日時 2023-09-12 16:17:52
合計ジャッジ時間 10,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
82,484 KB
testcase_01 AC 139 ms
82,504 KB
testcase_02 AC 188 ms
83,924 KB
testcase_03 AC 180 ms
83,632 KB
testcase_04 AC 142 ms
82,612 KB
testcase_05 AC 143 ms
82,468 KB
testcase_06 AC 574 ms
91,632 KB
testcase_07 AC 601 ms
90,120 KB
testcase_08 AC 579 ms
90,976 KB
testcase_09 AC 372 ms
88,212 KB
testcase_10 AC 275 ms
87,480 KB
testcase_11 AC 282 ms
85,956 KB
testcase_12 AC 277 ms
87,012 KB
testcase_13 AC 266 ms
85,568 KB
testcase_14 AC 268 ms
85,952 KB
testcase_15 AC 148 ms
82,528 KB
testcase_16 AC 147 ms
82,652 KB
testcase_17 AC 145 ms
82,572 KB
testcase_18 AC 274 ms
86,464 KB
testcase_19 AC 276 ms
86,164 KB
testcase_20 AC 270 ms
86,176 KB
testcase_21 AC 287 ms
86,344 KB
testcase_22 AC 1,383 ms
101,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import *

n = int(raw_input())
a = map(int, raw_input().split(' ' ))

def gao(a, v):
    for x in a:
        v[x] = 1
    n = len(a)
    for i in xrange(n):
        for j in xrange(n):
            if i == j:
                continue
            t = []
            for k in xrange(n):
                if k == i or k == j:
                    continue
                t.append(a[k])
            t.append(0)
            t[-1] = a[i] - a[j]
            gao(t, v)
            t[-1] = a[i] + a[j]
            gao(t, v)
            t[-1] = a[i] * a[j]
            gao(t, v)
            if a[j]:
                t[-1] = a[i] / a[j]
                gao(t, v)

for mask in xrange(1 << n):
    x = []
    y = []
    for i in xrange(n):
        if (mask >> i & 1):
            x.append(Fraction(a[i], 1))
        else:
            y.append(Fraction(a[i], 1))
    sx = {}
    sy = {}
    if not len(x) or not len(y):
        continue
    if n >= 6 and min(len(x), len(y)) <= 2:
        continue
    gao(x, sx)
    gao(y, sy)
    for v in sx:
        if v in sy:
            print 'YES'
            exit(0)
print 'NO'
0