結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
29,488 KB
testcase_01 AC 126 ms
29,624 KB
testcase_02 AC 127 ms
29,664 KB
testcase_03 AC 126 ms
29,620 KB
testcase_04 AC 126 ms
29,664 KB
testcase_05 AC 122 ms
29,536 KB
testcase_06 AC 128 ms
29,508 KB
testcase_07 AC 132 ms
29,672 KB
testcase_08 AC 136 ms
30,276 KB
testcase_09 AC 131 ms
29,532 KB
testcase_10 AC 129 ms
29,648 KB
testcase_11 AC 123 ms
29,472 KB
testcase_12 AC 123 ms
29,504 KB
testcase_13 AC 119 ms
29,720 KB
testcase_14 AC 125 ms
29,556 KB
testcase_15 AC 131 ms
29,612 KB
testcase_16 AC 124 ms
29,668 KB
testcase_17 AC 127 ms
29,540 KB
testcase_18 AC 123 ms
29,472 KB
testcase_19 AC 124 ms
29,676 KB
testcase_20 AC 123 ms
29,680 KB
testcase_21 AC 127 ms
29,716 KB
testcase_22 AC 124 ms
29,720 KB
testcase_23 AC 121 ms
29,664 KB
testcase_24 AC 127 ms
29,724 KB
testcase_25 AC 125 ms
29,660 KB
testcase_26 AC 120 ms
29,624 KB
testcase_27 AC 123 ms
29,616 KB
testcase_28 AC 137 ms
29,684 KB
testcase_29 AC 130 ms
30,004 KB
testcase_30 AC 122 ms
29,916 KB
testcase_31 AC 121 ms
29,672 KB
testcase_32 AC 122 ms
29,776 KB
testcase_33 AC 127 ms
30,128 KB
testcase_34 AC 129 ms
29,652 KB
testcase_35 AC 134 ms
29,984 KB
testcase_36 AC 132 ms
29,996 KB
testcase_37 AC 128 ms
29,712 KB
testcase_38 AC 128 ms
29,836 KB
testcase_39 AC 131 ms
30,268 KB
testcase_40 AC 131 ms
29,844 KB
testcase_41 AC 130 ms
29,848 KB
testcase_42 AC 131 ms
29,696 KB
testcase_43 AC 132 ms
29,616 KB
testcase_44 AC 126 ms
29,744 KB
testcase_45 AC 131 ms
30,156 KB
testcase_46 AC 128 ms
30,076 KB
testcase_47 AC 125 ms
29,836 KB
testcase_48 AC 121 ms
29,736 KB
testcase_49 AC 124 ms
29,780 KB
testcase_50 AC 125 ms
29,660 KB
testcase_51 AC 128 ms
29,680 KB
testcase_52 AC 137 ms
29,560 KB
testcase_53 AC 129 ms
29,664 KB
testcase_54 AC 132 ms
29,692 KB
testcase_55 AC 131 ms
29,600 KB
testcase_56 AC 127 ms
29,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import numpy as np

# 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(int(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(np.array((col.pop(), row), dtype=int))
    if(len(starPos) == 2):
        break


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

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

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

# 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