QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#319482#5583. Color TubeschmproWA 6ms9476kbPython31.8kb2024-02-02 17:06:432024-02-02 17:06:44

Judging History

你现在查看的是最新测评结果

  • [2024-02-02 17:06:44]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:9476kb
  • [2024-02-02 17:06:43]
  • 提交

answer

import sys
input=sys.stdin.readline
F=lambda:[*map(int,input().split())]
def move(i,j):
  if i==j:return
  ANS.append((i,j))
  h1=2
  while A[i][h1]==0:h1-=1
  x=A[i][h1]
  A[i][h1]=0
  if h1>=1:CNT[x]-=1
  idx1=0
  while POS[x][idx1]!=(i,h1):idx1+=1
  h2=0
  while A[j][h2]>0:h2+=1
  A[j][h2]=x
  if h2>=1:CNT[x]+=1
  POS[x][idx1]=(j,h2)
  idx2=0
  while POS[0][idx2]!=(j,h2):idx2+=1
  POS[0][idx2]=(i,h1)

def make_empty():
  p0=POS[0][0][0]
  for idx in range(1,3):
    if POS[0][idx][0]!=p0:move(p0,POS[0][idx][0])

N=int(input())
A=[[]]+[F()for _ in range(N+1)]
CNT=[0]*(N+1)
POS=[[]for _ in range(N+1)]
for n in range(1,N+2):
  for h in range(3):
    cur=A[n][h]
    if h>=1:CNT[cur]+=1
    POS[cur].append((n,h))

ANS=[]
NXT=[i+1 for i in range(N+1)];NXT[N]=1
PRV=[i-1 for i in range(N+1)];PRV[1]=N


cur=1
for _ in range(N):
  make_empty()
  #print(ANS,CNT,POS)
  pos_0=POS[0][0][0]
  while 1:
    if CNT[cur]<=1:cur=NXT[cur];continue
    idx=0
    while idx<3 and POS[cur][idx][1]<2:idx+=1
    if idx==3:cur=NXT[cur];continue
    else:break
  #print(ANS)
  POS[cur].sort(key=lambda x:-x[1])
  p1=POS[cur][0][0]
  move(p1,pos_0)
  p2=POS[cur][1][0];h=POS[cur][1][1]
  chk=1
  if h==2 or p1==p2:move(p2,pos_0)
  else:
    move(p2,p1)
    chk=0 #p1에 자리 없음
    move(p2,pos_0)
  p3=POS[cur][2][0];h=POS[cur][2][1]
  if h==2 or (h==1 or (p3==p2)) or (h==0 and p3==p2==p1):move(p3,pos_0)
  elif h==1:
    #print(ANS)
    move(p3,p2)
    move(p3,pos_0)
  else:
    if chk:
      move(p3,p1)
      move(p3,p2)
      move(p3,pos_0)
    else:
      move(p3,p2)
      move(p3,p2)
      move(p3,pos_0)

  nxt=NXT[cur]
  prv=PRV[cur]
  NXT[prv]=nxt
  PRV[nxt]=prv
  cur=nxt
print(len(ANS))
for ans in ANS:print(*ans)

详细

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 9476kb

input:

3
2 2 0
1 3 1
3 1 2
3 0 0

output:

15
1 4
1 4
2 1
3 2
3 1
2 3
2 3
2 1
4 2
4 2
3 2
4 3
2 4
3 4
3 4

result:

wrong answer Partially filled tube 2.