結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
コンテスト
ユーザー tanson
提出日時 2026-04-16 07:06:17
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 2,686 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,523 ms
コンパイル使用メモリ 704,696 KB
実行使用メモリ 54,500 KB
最終ジャッジ日時 2026-04-16 07:06:25
合計ジャッジ時間 7,246 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fun quicksort [] = []
  | quicksort (h::tl) =
    let 
        val (s, b) =
            List.foldl
                (fn (x, (small, big)) =>
                    if x <= h then (x::small, big)
                    else (small, x::big))
                ([], [])
                tl
    in
        (quicksort s) @ [h] @ (quicksort b)
    end


fun readInt () =
    valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)


fun intString n =
    if 0 <= n
    then Int.toString n
    else "-" ^ Int.toString (abs n)


val () =
    let
        val x1 = readInt ()
        val y1 = readInt ()
        val x2 = readInt ()
        val y2 = readInt ()
        val x3 = readInt ()
        val y3 = readInt ()

        val candidates =
            List.foldl (fn (l, acc) =>
                           l @ acc)
                       []
                       (List.tabulate (401, (fn x =>
                                               List.map (fn yy => (x - 200, yy))
                                                        (List.tabulate (401, (fn y => y - 200))))))

        val ans = List.find (fn (x, y) =>
                                let
                                    val d1 = (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)
                                    val d2 = (x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)
                                    val d3 = (x3 - x) * (x3 - x) + (y3 - y) * (y3 - y)
                                    val sorted = quicksort [d1, d2, d3]
                                in
                                    if List.nth (sorted, 0) = List.nth (sorted, 1) andalso List.nth (sorted, 0) * 2 = List.nth (sorted, 2)
                                    then
                                        (
                                          if List.nth (sorted, 2) = d1
                                          then (y2 - y) * (y3 - y) = (~1) * (x2 - x) * (x3 - x) andalso (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1) = d2
                                          else if List.nth (sorted, 2) = d2
                                          then (y1 - y) * (y3 - y) = (~1) * (x1 - x) * (x3 - x) andalso (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) = d1
                                          else (y2 - y) * (y1 - y) = (~1) * (x2 - x) * (x1 - x) andalso (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1) = d1
                                        )
                                    else false
                                end)
                            candidates
    in
        case ans of
            NONE =>
            print ("-1" ^ "\n")
          | SOME (x, y) => 
            print (intString x ^ " " ^ intString y ^ "\n")
    end

0