結果
問題 |
No.455 冬の大三角
|
ユーザー |
![]() |
提出日時 | 2016-12-06 21:45:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,307 bytes |
コンパイル時間 | 102 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-06-29 21:16:05 |
合計ジャッジ時間 | 3,318 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
# 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")