結果

問題 No.179 塗り分け
ユーザー regeregeregerege
提出日時 2015-10-22 23:15:22
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 2,181 bytes
コンパイル時間 7,666 ms
コンパイル使用メモリ 187,572 KB
実行使用メモリ 35,072 KB
最終ジャッジ日時 2024-04-10 12:50:41
合計ジャッジ時間 13,399 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
31,488 KB
testcase_01 AC 75 ms
30,976 KB
testcase_02 AC 86 ms
31,360 KB
testcase_03 WA -
testcase_04 AC 87 ms
31,488 KB
testcase_05 WA -
testcase_06 AC 90 ms
31,744 KB
testcase_07 WA -
testcase_08 AC 91 ms
31,616 KB
testcase_09 AC 88 ms
31,744 KB
testcase_10 AC 87 ms
31,488 KB
testcase_11 AC 86 ms
31,480 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 77 ms
30,720 KB
testcase_16 AC 88 ms
31,232 KB
testcase_17 WA -
testcase_18 AC 87 ms
31,336 KB
testcase_19 AC 87 ms
31,360 KB
testcase_20 WA -
testcase_21 AC 76 ms
30,720 KB
testcase_22 AC 75 ms
30,848 KB
testcase_23 AC 103 ms
34,992 KB
testcase_24 AC 76 ms
30,848 KB
testcase_25 AC 89 ms
31,616 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 74 ms
30,840 KB
testcase_32 AC 93 ms
32,640 KB
testcase_33 AC 75 ms
30,848 KB
testcase_34 AC 91 ms
31,744 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 77 ms
30,848 KB
testcase_38 WA -
testcase_39 AC 86 ms
31,360 KB
testcase_40 AC 87 ms
31,488 KB
testcase_41 AC 75 ms
30,464 KB
testcase_42 AC 85 ms
31,488 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 87 ms
31,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (261 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

let ``No.179 塗り分け`` () =
    let bitcount (bit:int) =
        let a = (bit &&& 0x55555555) + (bit >>> 1 &&& 0x55555555) in
        let b = (a &&& 0x33333333) + (a >>> 2 &&& 0x33333333) in
        let c = (b &&& 0x0F0F0F0F) + (b >>> 4 &&& 0x0F0F0F0F) in
        let d = (c &&& 0x00FF00FF) + (c >>> 8 &&& 0x00FF00FF) in
        (d &&& 0x0000FFFF) + (d >>> 16 &&& 0x0000FFFF)
    let bc l = Seq.map bitcount l |> Seq.sum
    let arr = stdin.ReadLine().Split(' ')
    let H = int(arr.[0])
    let W = int(arr.[0])
    // '#' と '.' を数値 1 と 0 に変換 (ビットに変換する)。 
    let read() =
        stdin.ReadLine()
        |> Seq.mapi (fun i c -> (int(c)%46%34) <<< i)
        |> Seq.reduce (|||)
    let bits = [ for i in 1..H -> read() ]
    let mask = (1 <<< W) - 1
    let c1 = bc bits
    let p =
        if c1 &&& 1 = 1 then 0
        else
            let c2 = c1/2
            let check l = bc l = c2
            // 総当たり
            // 衝突判定があり、ビットの総数÷2の数になれば一致したとみなす。
            let b =
                seq { for h in 1..H do for w in 1..W -> h,w }
                |> Seq.collect (fun (h,w) ->
                    let blank = List.init h (fun _ -> 0)
                    let r = List.map (fun n -> n >>> w &&& mask) bits
                    let l = List.map (fun n -> n <<< w &&& mask) bits
                    seq [
                        yield check r                               // →
                        yield check l                               // ←
                        yield check ((List.skip h bits)@blank)      // ↑
                        yield check (blank@(List.take (H-h) bits))  // ↓
                        yield check ((List.skip h r)@blank)         // ↗
                        yield check ((List.skip h l)@blank)         // ↖
                        yield check (blank@(List.take (H-h) r))     // ↘
                        yield check (blank@(List.take (H-h) l))     // ↙
                    ]
                )
                |> Seq.exists id
            if b then 1 else 0
    printfn "%s" ["NO";"YES";].[p]
``No.179 塗り分け`` ()
0