結果

問題 No.2596 Christmas Eve (Heuristic ver.)
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-11-28 14:27:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,161 ms / 1,224 ms
コード長 5,976 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,800 KB
スコア 4,991,845
最終ジャッジ日時 2023-12-23 20:37:03
合計ジャッジ時間 155,652 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,151 ms
87,244 KB
testcase_01 AC 1,152 ms
88,336 KB
testcase_02 AC 1,152 ms
86,808 KB
testcase_03 AC 1,150 ms
87,020 KB
testcase_04 AC 1,152 ms
86,884 KB
testcase_05 AC 1,152 ms
88,304 KB
testcase_06 AC 1,152 ms
88,432 KB
testcase_07 AC 1,153 ms
88,772 KB
testcase_08 AC 1,151 ms
88,580 KB
testcase_09 AC 1,153 ms
88,308 KB
testcase_10 AC 1,152 ms
88,104 KB
testcase_11 AC 1,151 ms
88,224 KB
testcase_12 AC 1,152 ms
87,452 KB
testcase_13 AC 1,152 ms
87,860 KB
testcase_14 AC 1,153 ms
88,116 KB
testcase_15 AC 1,151 ms
89,512 KB
testcase_16 AC 1,152 ms
87,336 KB
testcase_17 AC 1,151 ms
86,856 KB
testcase_18 AC 1,151 ms
88,956 KB
testcase_19 AC 1,152 ms
88,508 KB
testcase_20 AC 1,152 ms
87,776 KB
testcase_21 AC 1,151 ms
86,288 KB
testcase_22 AC 1,150 ms
88,784 KB
testcase_23 AC 1,152 ms
87,376 KB
testcase_24 AC 1,151 ms
87,768 KB
testcase_25 AC 1,151 ms
88,752 KB
testcase_26 AC 1,151 ms
88,396 KB
testcase_27 AC 1,152 ms
89,764 KB
testcase_28 AC 1,152 ms
87,940 KB
testcase_29 AC 1,149 ms
89,012 KB
testcase_30 AC 1,152 ms
86,788 KB
testcase_31 AC 1,152 ms
87,080 KB
testcase_32 AC 1,151 ms
87,964 KB
testcase_33 AC 1,151 ms
88,900 KB
testcase_34 AC 1,149 ms
87,924 KB
testcase_35 AC 1,151 ms
87,740 KB
testcase_36 AC 1,152 ms
88,416 KB
testcase_37 AC 1,153 ms
88,412 KB
testcase_38 AC 1,152 ms
88,604 KB
testcase_39 AC 1,151 ms
88,904 KB
testcase_40 AC 1,150 ms
88,448 KB
testcase_41 AC 1,151 ms
89,140 KB
testcase_42 AC 1,151 ms
88,260 KB
testcase_43 AC 1,151 ms
89,800 KB
testcase_44 AC 1,151 ms
87,664 KB
testcase_45 AC 1,151 ms
88,868 KB
testcase_46 AC 1,154 ms
87,688 KB
testcase_47 AC 1,152 ms
89,144 KB
testcase_48 AC 1,155 ms
88,228 KB
testcase_49 AC 1,155 ms
86,184 KB
testcase_50 AC 1,161 ms
88,060 KB
testcase_51 AC 1,155 ms
86,832 KB
testcase_52 AC 1,154 ms
84,880 KB
testcase_53 AC 1,156 ms
86,604 KB
testcase_54 AC 1,154 ms
88,408 KB
testcase_55 AC 1,151 ms
89,240 KB
testcase_56 AC 1,152 ms
88,628 KB
testcase_57 AC 1,151 ms
88,244 KB
testcase_58 AC 1,151 ms
88,300 KB
testcase_59 AC 1,151 ms
88,780 KB
testcase_60 AC 1,151 ms
87,440 KB
testcase_61 AC 1,151 ms
87,664 KB
testcase_62 AC 1,151 ms
85,096 KB
testcase_63 AC 1,151 ms
88,744 KB
testcase_64 AC 1,151 ms
88,608 KB
testcase_65 AC 1,150 ms
87,784 KB
testcase_66 AC 1,151 ms
87,856 KB
testcase_67 AC 1,152 ms
88,736 KB
testcase_68 AC 1,150 ms
88,636 KB
testcase_69 AC 1,151 ms
87,820 KB
testcase_70 AC 1,152 ms
86,964 KB
testcase_71 AC 1,151 ms
88,440 KB
testcase_72 AC 1,152 ms
87,548 KB
testcase_73 AC 1,151 ms
87,056 KB
testcase_74 AC 1,150 ms
88,436 KB
testcase_75 AC 1,152 ms
87,656 KB
testcase_76 AC 1,154 ms
88,640 KB
testcase_77 AC 1,152 ms
89,000 KB
testcase_78 AC 1,152 ms
88,892 KB
testcase_79 AC 1,154 ms
88,756 KB
testcase_80 AC 1,152 ms
87,640 KB
testcase_81 AC 1,150 ms
88,332 KB
testcase_82 AC 1,151 ms
88,360 KB
testcase_83 AC 1,150 ms
87,384 KB
testcase_84 AC 1,150 ms
88,652 KB
testcase_85 AC 1,151 ms
87,688 KB
testcase_86 AC 1,151 ms
88,492 KB
testcase_87 AC 1,151 ms
87,776 KB
testcase_88 AC 1,152 ms
89,260 KB
testcase_89 AC 1,151 ms
89,108 KB
testcase_90 AC 1,150 ms
87,724 KB
testcase_91 AC 1,152 ms
89,024 KB
testcase_92 AC 1,151 ms
86,680 KB
testcase_93 AC 1,151 ms
88,796 KB
testcase_94 AC 1,151 ms
88,956 KB
testcase_95 AC 1,151 ms
89,384 KB
testcase_96 AC 1,153 ms
86,580 KB
testcase_97 AC 1,151 ms
88,172 KB
testcase_98 AC 1,153 ms
86,836 KB
testcase_99 AC 1,152 ms
88,372 KB
testcase_100 AC 1,152 ms
88,796 KB
testcase_101 AC 1,150 ms
87,988 KB
testcase_102 AC 1,150 ms
89,240 KB
testcase_103 AC 1,149 ms
87,724 KB
testcase_104 AC 1,152 ms
87,084 KB
testcase_105 AC 1,152 ms
88,792 KB
testcase_106 AC 1,153 ms
88,384 KB
testcase_107 AC 1,151 ms
88,292 KB
testcase_108 AC 1,151 ms
86,048 KB
testcase_109 AC 1,150 ms
88,572 KB
testcase_110 AC 1,150 ms
89,672 KB
testcase_111 AC 1,151 ms
87,692 KB
testcase_112 AC 1,151 ms
87,604 KB
testcase_113 AC 1,151 ms
86,776 KB
testcase_114 AC 1,152 ms
88,588 KB
testcase_115 AC 1,151 ms
88,340 KB
testcase_116 AC 1,153 ms
88,496 KB
testcase_117 AC 1,151 ms
88,840 KB
testcase_118 AC 1,154 ms
88,192 KB
testcase_119 AC 1,151 ms
87,668 KB
testcase_120 AC 1,152 ms
86,264 KB
testcase_121 AC 1,152 ms
87,168 KB
testcase_122 AC 1,152 ms
87,124 KB
testcase_123 AC 1,151 ms
88,840 KB
testcase_124 AC 1,152 ms
88,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import time
from math import exp
def isvalid(tree):
    return e[tree[3]]<a[tree[0]] and a[tree[0]]<c[tree[1]] and a[tree[0]]<c[tree[2]]

def high(tree):
    return b[tree[0]]+d[tree[1]]+d[tree[2]]+f[tree[3]]

def row_score(trees):
    global mini_pos,maxi_pos
    mini=40000
    maxi=0
    cnt=0
    for i in trees:
        now=high(i)
        if now<mini:
            mini=now
            mini_pos=cnt
        if now>maxi:
            maxi=now
            maxi_pos=cnt
        cnt+=1
    return maxi-mini

def score(trees):
    wa=0
    use=[]
    for i in trees:
        use.append(high(i))
        wa+=use[-1]
    ret=0
    for i in use:
        ret+=((i*N)-wa)**2
    return ret

st=time.time()
N,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=list(map(int,input().split()))
e=list(map(int,input().split()))
f=list(map(int,input().split()))
tip=list(zip(a,b,range(N)))
center=list(zip(c,d,range(N*2)))
stem=list(zip(e,f,range(N)))
tip.sort(reverse=True)
center.sort(reverse=True)
stem.sort(reverse=True)
tip_stock=set(range(N))
center_stock=set(range(N*2))
stem_stock=set(range(N))
tree=[]
for i in range(M):
    while stem[-1][0]>=tip[-1][0]:
        tip.pop()
    while tip[-1][0]>=center[-1][0]:
        center.pop()
    tree.append([tip[-1][2],center[-1][2],center[-2][2],stem[-1][2]])
    tip_stock.discard(tip[-1][2])
    center_stock.discard(center[-1][2])
    center_stock.discard(center[-2][2])
    stem_stock.discard(stem[-1][2])
    center.pop()
    center.pop()
    tip.pop()
    stem.pop()
tip_stock=list(tip_stock)
center_stock=list(center_stock)
stem_stock=list(stem_stock)
mini_pos=-1
maxi_pos=-1
now=row_score(tree)
t_st=50000
t_gl=1
count=0
best=now
fin=[i[:] for i in tree]
while time.time()-st<1.1:
    count+=1
    now_temp=t_st*(t_gl/t_st)**((time.time()-st)*0.90909)
    befmi=mini_pos
    befma=maxi_pos
    if random.random()<0.7:
        if random.random()<0.5:
            lf=mini_pos
        else:
            lf=maxi_pos
        ri=random.randint(0,M-1)
        if lf==ri:
            ri=(ri+1)%M
        if random.random()<0.25:
            tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0]
            if not(isvalid(tree[lf]) and isvalid(tree[ri])):
                tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0]
                else:
                    now=sc
        elif random.random()<0.3333:
            tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2]
            if not(isvalid(tree[lf]) and isvalid(tree[ri])):
                tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][2],tree[ri][2]=tree[ri][2],tree[lf][2]
                else:
                    now=sc
        else:
            if random.random()<0.5:
                tree[lf][1],tree[lf][2]=tree[lf][2],tree[lf][1]
            if random.random()<0.5:
                tree[ri][1],tree[ri][2]=tree[ri][2],tree[ri][1]
            tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1]
            if not(isvalid(tree[lf]) and isvalid(tree[ri])):
                tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][1],tree[ri][1]=tree[ri][1],tree[lf][1]
                else:
                    now=sc
    else:
        if random.random()<0.5:
            lf=mini_pos
        else:
            lf=maxi_pos
        if random.random()<0.25:
            pos=random.randint(0,len(tip_stock)-1)
            tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0]
            if not(isvalid(tree[lf])):
                tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][0],tip_stock[pos]=tip_stock[pos],tree[lf][0]
                else:
                    now=sc
        elif random.random()<0.33333:
            pos=random.randint(0,len(stem_stock)-1)
            tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3]
            if not(isvalid(tree[lf])):
                tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][3],stem_stock[pos]=stem_stock[pos],tree[lf][3]
                else:
                    now=sc
        else:
            if random.random()<0.5:
                tree[lf][1],tree[lf][2]=tree[lf][2],tree[lf][1]
            pos=random.randint(0,len(center_stock)-1)
            tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2]
            if not(isvalid(tree[lf])):
                tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2]
            else:
                sc=row_score(tree)
                if not(sc<now or random.random()<exp((now-sc)/now_temp)):
                    maxi_pos=befma
                    mini_pos=befmi
                    tree[lf][2],center_stock[pos]=center_stock[pos],tree[lf][2]
                else:
                    now=sc
    if best>now:
        fin=[i[:] for i in tree]
        best=now
for i in fin:
    print(*(map(lambda x:x+1,i)))
0