Skip to content

Commit 0b27a31

Browse files
committed
happy birth day
1 parent 43e159c commit 0b27a31

File tree

2 files changed

+230
-0
lines changed

2 files changed

+230
-0
lines changed

python/plat5/19235.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
arr = [[0]*10 for _ in range(10)]
5+
6+
N = int(input())
7+
point = 0
8+
# move1 -> check -> done? yes-> move2 -> check -> done? -> move2 ....
9+
# no-> check2 -> done? -> move2 -
10+
#red to blue and green
11+
def move1(x,y,mode):
12+
if mode==1:
13+
nx,ny=x,4
14+
while ny<10 and not arr[nx][ny]:
15+
ny+=1
16+
arr[nx][ny-1]=arr[x][y]
17+
nx,ny=4,y
18+
while nx<10 and not arr[nx][ny]:
19+
nx+=1
20+
arr[nx-1][ny]=arr[x][y]
21+
arr[x][y]=0
22+
#가로
23+
elif mode==2:
24+
nx,ny=x,4
25+
while ny<10 and not arr[nx][ny]:
26+
ny+=1
27+
arr[nx][ny-2]=arr[nx][ny-1]=arr[x][y]
28+
nx,ny=4,y
29+
while nx<10 and arr[nx][ny]==0 and arr[nx][ny+1]==0:
30+
nx+=1
31+
arr[nx-1][ny]=arr[nx-1][ny+1]=arr[x][y]
32+
arr[x][y],arr[x][y+1]=0,0
33+
else:
34+
nx,ny=x,4
35+
while ny<10 and arr[nx][ny]==0 and arr[nx+1][ny]==0:
36+
ny+=1
37+
arr[nx][ny-1]=arr[nx+1][ny-1]=arr[x][y]
38+
nx,ny=4,y
39+
while nx < 10 and not arr[nx][ny]:
40+
nx+=1
41+
arr[nx-2][ny]=arr[nx-1][ny]=arr[x][y]
42+
arr[x][y],arr[x+1][y]=0,0
43+
# check special zone
44+
def check2():
45+
ch = [0,0]
46+
for x in range(4,6):
47+
for y in range(4):
48+
if arr[x][y]:
49+
ch[x%2]=1
50+
break
51+
ch = sum(ch)
52+
if ch:
53+
for x in range(9,3,-1):
54+
for y in range(4):
55+
arr[x][y] = arr[x-ch][y]
56+
ch = [0,0]
57+
for y in range(4,6):
58+
for x in range(4):
59+
if arr[x][y]:
60+
ch[y%2]=1
61+
break
62+
ch = sum(ch)
63+
if ch:
64+
for y in range(9,3,-1):
65+
for x in range(4):
66+
arr[x][y] = arr[x][y-ch]
67+
68+
# check point
69+
def check():
70+
global point
71+
check_done = False
72+
x = 6
73+
while x<10:
74+
if arr[x][0] and arr[x][1] and arr[x][2] and arr[x][3]:
75+
for i in range(4):
76+
arr[x][i] = 0
77+
point+=1
78+
check_done=True
79+
x+=1
80+
y = 6
81+
while y<10:
82+
if arr[0][y] and arr[1][y] and arr[2][y] and arr[3][y]:
83+
for i in range(4):
84+
arr[i][y] = 0
85+
check_done = True
86+
point+=1
87+
y+=1
88+
return check_done
89+
90+
def move2():
91+
for y in range(8,3,-1):
92+
for x in range(4):
93+
if arr[x][y]:
94+
if x<3 and arr[x][y]==arr[x+1][y]:
95+
ny=y+1
96+
while ny<10 and arr[x][ny]==0 and arr[x+1][ny]==0:
97+
ny+=1
98+
if ny-1!=y:
99+
arr[x][ny-1]=arr[x+1][ny-1]=arr[x][y]
100+
arr[x][y]=arr[x+1][y]=0
101+
elif x>0 and arr[x][y]==arr[x-1][y]:
102+
ny=y+1
103+
while ny<10 and arr[x][ny]==0 and arr[x-1][ny]==0:
104+
ny+=1
105+
if ny-1!=y:
106+
arr[x][ny-1]=arr[x-1][ny-1]=arr[x][y]
107+
arr[x][y]=arr[x-1][y]=0
108+
else:
109+
ny=y+1
110+
while ny<10 and arr[x][ny]==0:
111+
ny+=1
112+
if ny-1!=y:
113+
arr[x][ny-1]=arr[x][y]
114+
arr[x][y]=0
115+
116+
for x in range(8,3,-1):
117+
for y in range(4):
118+
if arr[x][y]:
119+
if y<3 and arr[x][y]==arr[x][y+1]:
120+
nx = x+1
121+
while nx<10 and arr[nx][y]==0 and arr[nx][y+1]==0:
122+
nx+=1
123+
if nx-1!=x:
124+
arr[nx-1][y]=arr[nx-1][y+1]=arr[x][y]
125+
arr[x][y]=arr[x][y+1]=0
126+
elif y>0 and arr[x][y]==arr[x][y-1]:
127+
nx = x+1
128+
while nx<10 and arr[nx][y]==0 and arr[nx][y-1]==0:
129+
nx+=1
130+
if nx-1!=x:
131+
arr[nx-1][y]=arr[nx][y-1]=arr[x][y]
132+
arr[x][y]=arr[x][y-1]=0
133+
else:
134+
nx=x+1
135+
while nx<10 and arr[nx][y]==0:
136+
nx+=1
137+
if nx-1!=x:
138+
arr[nx-1][y]=arr[x][y]
139+
arr[x][y]=0
140+
141+
142+
def checkLast():
143+
ans = 0
144+
for x in range(4):
145+
for y in range(6,10):
146+
if arr[x][y]:ans+=1
147+
if arr[y][x]:ans+=1
148+
return ans
149+
def printBoard():
150+
for y in range(10):
151+
print(' '.join(map(str,arr[y])))
152+
print()
153+
for i in range(1,N+1):
154+
t,x,y = map(int,input().split())
155+
if t==1:
156+
arr[x][y]=i
157+
elif t==2:
158+
arr[x][y]=i
159+
arr[x][y+1]=i
160+
else:
161+
arr[x+1][y]=i
162+
arr[x][y]=i
163+
#printBoard()
164+
move1(x,y,t)
165+
#printBoard()
166+
while check():
167+
#printBoard()
168+
move2()
169+
#printBoard()
170+
check2()
171+
#printBoard()
172+
print(point)
173+
print(checkLast())

python/plat5/9202.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
class myDict(object):
5+
def __init__(self):
6+
self.root = {}
7+
8+
def insert(self, now, word, idx):
9+
if len(word)==idx:
10+
now['*']=word
11+
return
12+
if word[idx] not in now:
13+
now[word[idx]]={}
14+
self.insert(now[word[idx]],word,idx+1)
15+
return
16+
17+
18+
myD = myDict()
19+
N = int(input())
20+
for _ in range(N):
21+
row = input().strip()
22+
myD.insert(myD.root,row,0)
23+
boggle = []
24+
visited = [[False]*4 for _ in range(4)]
25+
dy,dx = [-1,-1,-1,0,1,1,1,0],[-1,0,1,1,1,0,-1,-1]
26+
word_set = set()
27+
score_Dict = {1:0,2:0,3:1,4:1,5:2,6:3,7:5,8:11}
28+
def dfs(y,x,now,length):
29+
global boggle,visited
30+
if length>8:return
31+
if boggle[y][x] in now:
32+
if '*' in now[boggle[y][x]]:
33+
word_set.add(now[boggle[y][x]]['*'])
34+
for i in range(8):
35+
ny,nx=y+dy[i],x+dx[i]
36+
if ny<0 or nx<0 or ny>=4 or nx>=4:continue
37+
if visited[ny][nx]:continue
38+
visited[ny][nx]=True
39+
dfs(ny,nx,now[boggle[y][x]],length+1)
40+
visited[ny][nx]=False
41+
input()
42+
M = int(input())
43+
for i in range(M):
44+
boggle = [input().strip() for _ in range(4)]
45+
if i<M-1:
46+
input()
47+
for y in range(4):
48+
for x in range(4):
49+
visited[y][x]=True
50+
dfs(y,x,myD.root,0)
51+
visited[y][x]=False
52+
total_score = 0
53+
word_list = sorted(word_set)
54+
for word in word_set:
55+
total_score+=score_Dict[len(word)]
56+
print(total_score,min(word_set,key=lambda x : (-len(x),x)),len(word_set))
57+
word_set = set()

0 commit comments

Comments
 (0)