結果

問題 No.506 限られたジャパリまん
ユーザー mbanmban
提出日時 2017-04-28 19:25:10
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,825 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 108,716 KB
実行使用メモリ 34,012 KB
最終ジャッジ日時 2023-09-10 12:54:04
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
22,772 KB
testcase_01 AC 61 ms
22,752 KB
testcase_02 AC 62 ms
20,792 KB
testcase_03 AC 60 ms
22,828 KB
testcase_04 WA -
testcase_05 AC 62 ms
20,708 KB
testcase_06 AC 61 ms
20,780 KB
testcase_07 WA -
testcase_08 AC 438 ms
24,852 KB
testcase_09 AC 231 ms
24,824 KB
testcase_10 AC 65 ms
22,792 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 61 ms
20,732 KB
testcase_14 WA -
testcase_15 AC 63 ms
18,712 KB
testcase_16 AC 349 ms
24,928 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int H, W, K, P;
    private int[] x, y;
    private string[] N;

    private void Scan()
    {
        string[] line = Console.ReadLine().Split(' ');
        H = int.Parse(line[0]);
        W = int.Parse(line[1]);
        K = int.Parse(line[2]);
        P = int.Parse(line[3]);
        x = new int[K];
        y = new int[K];
        N = new string[K];
        for (int i = 0; i < K; i++)
        {
            line = Console.ReadLine().Split(' ');
            x[i] = int.Parse(line[0]);
            y[i] = int.Parse(line[1]);
            N[i] = line[2];
        }
    }

    public void Solve()
    {
        Scan();
        long max = -1;
        int ans = 0;

        for (int i = 0; i < (1 << K); i++)
        {
            if (BitCount(i) != P)
            {
                continue;
            }
            long cnt = Count(i);
            if (max < cnt)
            {
                ans = i;
                max = cnt;
            }
        }
        Console.WriteLine(max);

        for (int i = 0; i < K; i++)
        {
            int j = 1 << i;
            if ((ans & j) != 0)
            {
                Console.WriteLine(N[i]);
            }
        }
    }

    private long Count(int i)
    {
        var d = new Dictionary<Pair<int, int>, bool>();
        for (int j = 0; j < K; j++)
        {
            int k = 1 << j;
            if ((i & k) == 0)
            {
                d[new Pair<int, int>(x[j], y[j])] = true;
            }
        }
        var dp = new long[H + 1, W + 1];
        dp[0, 0] = 1;
        for (int j = 0; j <= H; j++)
        {
            for (int k = 0; k <= W; k++)
            {
                bool o;
                if (d.TryGetValue(new Pair<int, int>(j, k), out o)) continue;
                if (j < H)
                {
                    dp[j + 1, k] += dp[j, k];
                    dp[j + 1, k] %= (int)1e9 + 7;
                }
                if (k < W)
                {
                    dp[j, k + 1] += dp[j, k];
                    dp[j, k + 1] %= (int)1e9 + 7;
                }
            }
        }
        return dp[H, W];
    }

    private int BitCount(int n)
    {
        int cnt = 0;
        for (int i = 0; i < K; i++)
        {
            if (n % 2 == 1)
            {
                cnt++;
            }
            n /= 2;
        }
        return cnt;
    }
}

struct Pair<F, S>
{
    public F First;
    public S Second;
    public Pair(F f, S s)
    {
        First = f;
        Second = s;
    }
}

0