結果
問題 |
No.5022 XOR Printer
|
ユーザー |
![]() |
提出日時 | 2025-07-26 15:06:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,850 ms / 2,000 ms |
コード長 | 3,628 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,656 KB |
実行使用メモリ | 92,876 KB |
スコア | 5,065,387,905 |
最終ジャッジ日時 | 2025-07-26 15:07:43 |
合計ジャッジ時間 | 96,417 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
import copy import time start_time = time.time() def change(num): re = [] for i in range(19,-1,-1): if 2**i <= num: num -= 2**i re.append(1) else: re.append(0) re.reverse() return re def go(s,g): if s[0] < g[0]: for i in range(g[0]-s[0]): ans.append('D') else: for i in range(s[0]-g[0]): ans.append('U') if s[1] < g[1]: for i in range(g[1]-s[1]): ans.append('R') else: for i in range(s[1]-g[1]): ans.append('L') n,t = map(int,input().split()) al = [] ans = [] al_two = [] now_num = 0 for i in range(n): s = [int(_) for _ in input().split()] al.append(s) other_s = [] for j in range(n): other_s.append(change(s[j])) al_two.append(other_s) score = 0 for i in range(n): for j in range(n): score += al[i][j] turn = 0 f_al = copy.deepcopy(al) f_al_two = copy.deepcopy(al_two) f_now_num = 0 f_score = score max_score = 0 finaly_ans = 0 road = [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (0, 9), (1, 9), (1, 8), (1, 7), (1, 6), (1, 5), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (3, 9), (3, 8), (3, 7), (3, 6), (3, 5), (3, 4), (3, 3), (3, 2), (3, 1), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), (5, 9), (5, 8), (5, 7), (5, 6), (5, 5), (5, 4), (5, 3), (5, 2), (5, 1), (5, 0), (6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6), (6, 7), (6, 8), (6, 9), (7, 9), (7, 8), (7, 7), (7, 6), (7, 5), (7, 4), (7, 3), (7, 2), (7, 1), (7, 0), (8, 0), (8, 1), (8, 2), (8, 3), (8, 4), (8, 5), (8, 6), (8, 7), (8, 8), (8, 9), (9, 9), (9, 8), (9, 7), (9, 6), (9, 5), (9, 4), (9, 3), (9, 2), (9, 1), (9, 0)] import random while (time.time()-start_time)*1000 <= 1800: ans = [] al = copy.deepcopy(f_al) al_two = copy.deepcopy(f_al_two) now_num = 0 score = f_score turn = 0 for i in range(16,20): best_node = (-1,-1) best_node_num = float('inf') for j in range(n): for l in range(n): next = change(now_num^al[j][l]) if next[i] == 1: if al[j][l] < best_node_num: best_node = (j,l) best_node_num = al[j][l] if turn+(best_node[0]+best_node[1]-2)*2+1 <= t: go((0,0),best_node) ans.append('C') now_num = now_num^al[best_node[0]][best_node[1]] go(best_node,(0,0)) turn += (best_node[0]+best_node[1])*2+1 now_node=(0,0) for k in road: j,l = k[0],k[1] if turn+abs(now_node[0]-j)+abs(now_node[1]-l)<=t: if al[j][l]^now_num > al[j][l]: go(now_node,(j,l)) turn = turn+abs(now_node[0]-j)+abs(now_node[1]-l) now_node = (j,l) if turn + 1 <= t: turn += 1 ans.append('W') score += ((al[j][l]^now_num)-al[j][l]) al[j][l] = (al[j][l]^now_num) al_two[j][l] = change(al[j][l]) elif random.random() < ((19-i)/10)**2: go(now_node,(j,l)) turn = turn+abs(now_node[0]-j)+abs(now_node[1]-l) now_node = (j,l) if turn + 1 <= t: turn += 1 ans.append('W') score += ((al[j][l]^now_num)-al[j][l]) al[j][l] = (al[j][l]^now_num) al_two[j][l] = change(al[j][l]) if turn+now_node[0]+now_node[1] <= t: turn += now_node[0] turn += now_node[1] go(now_node,(0,0)) else: continue if score > max_score: max_score = score finaly_ans = ans[:] #print(max_score) for i in finaly_ans: print(i)