結果

問題 No.455 冬の大三角
ユーザー amowweeamowwee
提出日時 2016-12-06 21:45:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 8,992 KB
最終ジャッジ日時 2023-09-12 08:30:59
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,216 KB
testcase_01 AC 16 ms
8,088 KB
testcase_02 AC 16 ms
8,084 KB
testcase_03 AC 15 ms
8,144 KB
testcase_04 AC 16 ms
8,164 KB
testcase_05 AC 16 ms
8,104 KB
testcase_06 AC 16 ms
8,160 KB
testcase_07 AC 16 ms
8,220 KB
testcase_08 AC 19 ms
8,992 KB
testcase_09 AC 17 ms
8,104 KB
testcase_10 AC 16 ms
8,048 KB
testcase_11 AC 16 ms
8,088 KB
testcase_12 AC 16 ms
8,148 KB
testcase_13 AC 16 ms
8,084 KB
testcase_14 AC 16 ms
8,088 KB
testcase_15 AC 16 ms
8,092 KB
testcase_16 AC 16 ms
8,084 KB
testcase_17 AC 16 ms
8,240 KB
testcase_18 AC 16 ms
8,128 KB
testcase_19 AC 16 ms
8,112 KB
testcase_20 AC 16 ms
8,208 KB
testcase_21 AC 16 ms
8,112 KB
testcase_22 AC 15 ms
8,116 KB
testcase_23 AC 16 ms
8,164 KB
testcase_24 AC 16 ms
8,088 KB
testcase_25 AC 16 ms
8,252 KB
testcase_26 AC 16 ms
8,084 KB
testcase_27 AC 16 ms
8,080 KB
testcase_28 AC 16 ms
8,148 KB
testcase_29 AC 18 ms
8,688 KB
testcase_30 AC 17 ms
8,604 KB
testcase_31 AC 17 ms
8,064 KB
testcase_32 AC 16 ms
8,088 KB
testcase_33 AC 18 ms
8,772 KB
testcase_34 AC 17 ms
8,168 KB
testcase_35 AC 17 ms
8,488 KB
testcase_36 AC 18 ms
8,564 KB
testcase_37 AC 16 ms
8,212 KB
testcase_38 AC 17 ms
8,076 KB
testcase_39 AC 18 ms
8,820 KB
testcase_40 AC 18 ms
8,504 KB
testcase_41 AC 18 ms
8,528 KB
testcase_42 AC 18 ms
8,592 KB
testcase_43 AC 17 ms
8,076 KB
testcase_44 AC 16 ms
8,076 KB
testcase_45 AC 18 ms
8,672 KB
testcase_46 AC 18 ms
8,564 KB
testcase_47 AC 18 ms
8,508 KB
testcase_48 AC 17 ms
8,148 KB
testcase_49 AC 16 ms
8,088 KB
testcase_50 AC 16 ms
8,088 KB
testcase_51 AC 16 ms
8,076 KB
testcase_52 AC 17 ms
8,124 KB
testcase_53 AC 16 ms
8,072 KB
testcase_54 AC 16 ms
8,068 KB
testcase_55 AC 17 ms
8,080 KB
testcase_56 AC 16 ms
8,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8

# Sieve of Eratosthenes
def sieve(a,b):
    if(abs(a)<abs(b)):
        temp = a
        a = b
        b = temp
    
    while(b):
        temp = a
        a = b
        b = temp%b
        
    return abs(a)

H,W = map(int,input().split())

# get 2 stars position
starPos = []
for row in range(H):
    col = [i for i, char in enumerate(input()) if char == "*"] 
    while(col):
        starPos.append((col.pop(), row))
    if(len(starPos) == 2):
        break


# star1 -> star2 vector
vec = ( starPos[1][0] - starPos[0][0], starPos[1][1] - starPos[0][1] )

div = sieve(vec[0],vec[1])
vec = ( vec[0] / div, vec[1] / div)

# enumerate lattice point on the star1--star2 line
lattice = []
p = starPos[0]
while(0 <= p[0] and W > p[0] and 0 <= p[1] and H > p[1] ):
    lattice.append(p)
    p = (p[0]+vec[0], p[1]+vec[1])
p = starPos[0]
while(0 <= p[0] and W > p[0] and 0 <= p[1] and H > p[1] ):
    lattice.append(p)
    p = (p[0]-vec[0], p[1]-vec[1])

# get 3rd star position
for thirdPos in [(x,y) for y in range(H) for x in range(W)]:
    if not thirdPos in lattice:
        starPos.append(thirdPos)
        break

# print result
sky = [["-" for w in range(W)] for h in range(H)]
for i in range(3):
    sky[starPos[i][1]][starPos[i][0]] = "*"
print("\n".join(["".join(s) for s in sky]), "\n")
0