結果
| 問題 |
No.455 冬の大三角
|
| コンテスト | |
| ユーザー |
amowwee
|
| 提出日時 | 2016-12-06 21:32:03 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 575 ms / 2,000 ms |
| コード長 | 1,247 bytes |
| コンパイル時間 | 269 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,784 KB |
| 最終ジャッジ日時 | 2024-11-28 03:15:44 |
| 合計ジャッジ時間 | 35,429 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 |
ソースコード
# 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")
amowwee