QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#319480#5583. Color TubeschmproWA 10ms9532kbPython31.8kb2024-02-02 16:58:232024-02-02 16:58:23

Judging History

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

  • [2024-02-02 16:58:23]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:9532kb
  • [2024-02-02 16:58:23]
  • 提交

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 and (p3==p1) 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: 100
Accepted
time: 10ms
memory: 9472kb

input:

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

output:

17
1 4
1 4
2 1
3 2
3 1
2 3
2 3
2 1
4 2
4 2
3 4
3 2
4 3
4 3
3 4
3 4
3 4

result:

ok correct

Test #2:

score: 0
Accepted
time: 3ms
memory: 9392kb

input:

1
0 0 0
1 1 1

output:

3
2 1
2 1
2 1

result:

ok correct

Test #3:

score: 0
Accepted
time: 10ms
memory: 9476kb

input:

2
2 1 0
2 1 0
2 1 0

output:

10
1 2
1 3
2 1
2 1
3 2
3 1
3 2
2 3
2 3
2 3

result:

ok correct

Test #4:

score: 0
Accepted
time: 7ms
memory: 9532kb

input:

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

output:

13
2 1
3 1
4 1
2 3
2 4
3 2
3 2
4 3
4 2
4 3
3 4
3 4
3 4

result:

ok correct

Test #5:

score: 0
Accepted
time: 10ms
memory: 9448kb

input:

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

output:

13
1 3
2 3
4 3
1 2
1 4
2 1
2 1
4 2
4 1
4 2
2 4
2 4
2 4

result:

ok correct

Test #6:

score: 0
Accepted
time: 3ms
memory: 9532kb

input:

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

output:

13
1 4
2 4
3 4
1 2
1 3
2 1
2 1
3 2
3 1
3 2
2 3
2 3
2 3

result:

ok correct

Test #7:

score: 0
Accepted
time: 10ms
memory: 9460kb

input:

6
0 0 0
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6

output:

27
2 1
3 1
4 1
2 3
2 4
5 2
6 2
7 2
7 6
7 5
3 7
3 7
4 3
4 7
4 3
6 4
5 6
5 4
6 4
5 6
3 5
3 5
3 5
6 3
4 3
6 4
6 3

result:

ok correct

Test #8:

score: -100
Wrong Answer
time: 7ms
memory: 9476kb

input:

6
0 0 0
1 5 6
1 2 6
1 2 3
4 2 3
4 5 3
4 5 6

output:

28
4 1
5 1
6 1
4 5
4 6
2 4
3 4
7 4
7 3
7 2
5 7
3 5
3 7
5 7
5 3
5 3
3 5
2 5
6 3
6 2
6 5
2 6
7 6
2 6
2 7
7 2
3 2
3 2

result:

wrong answer Mixed colors in tube 2.