結果

問題 No.506 限られたジャパリまん
ユーザー mbanmban
提出日時 2017-04-21 23:20:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,071 bytes
コンパイル時間 2,812 ms
コンパイル使用メモリ 105,924 KB
実行使用メモリ 29,088 KB
最終ジャッジ日時 2023-09-10 12:52:23
合計ジャッジ時間 5,306 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
22,720 KB
testcase_01 AC 57 ms
20,712 KB
testcase_02 AC 58 ms
20,656 KB
testcase_03 AC 59 ms
22,664 KB
testcase_04 WA -
testcase_05 AC 63 ms
22,760 KB
testcase_06 AC 61 ms
22,760 KB
testcase_07 WA -
testcase_08 AC 113 ms
27,036 KB
testcase_09 AC 82 ms
24,904 KB
testcase_10 AC 59 ms
22,728 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 57 ms
20,760 KB
testcase_14 WA -
testcase_15 AC 58 ms
20,672 KB
testcase_16 AC 100 ms
24,880 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 62 ms
20,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.IO;

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

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream source)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray()
    {
        Next();
        Index = S.Length;
        return S.ToArray();
    }
    public int[] IntArray()
    {
        return StringArray().Select(int.Parse).ToArray();
    }
    public long[] LongArray()
    {
        return StringArray().Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

class Magatro
{
    int N;
    public void Solve()
    {
        var cin = new Scanner(Console.OpenStandardInput());
        int h = cin.NextInt();
        int w = cin.NextInt();
        int k = cin.NextInt();
        int p = cin.NextInt();
        int[] x = new int[k];
        int[] y = new int[k];
        string[] n = new string[k];
        int mod = (int)1e9 + 7;

        for (int i = 0; i < k; i++)
        {
            x[i] = cin.NextInt();
            y[i] = cin.NextInt();
            n[i] = cin.Next();
        }
        bool[] ans = null;
        int max = 0;

        for (int i = 0; i <= 1 << k; i++)
        {
            bool[] b = new bool[k];
            int cnt = 0;
            int cpi = i;
            for(int j = 0; j < k; j++)
            {
                if(cpi%2 == 1)
                {
                    cnt++;
                    b[j] = true;
                }
                cpi /= 2;
            }
            if (cnt != p)
            {
                continue;
            }
            int[,] tr = new int[h + 1, w + 1];
            for(int j = 0; j < k; j++)
            {
                if (!b[j])
                {
                    tr[x[j], y[j]] = -1;
                }
            }

            tr[0, 0] = 1;
            for(int j = 0; j <= h; j++)
            {
                for(int l = 0; l <= w; l++)
                {
                    if (tr[j, l] == -1) continue;
                    if (j + 1 <= h)
                    {
                        if (tr[j + 1, l] != -1)
                        {
                            tr[j + 1, l] += tr[j, l];
                            tr[j + 1, l] %= mod;
                        }
                    }
                    if (l + 1 <= w)
                    {
                        if (tr[j, l+1] != -1)
                        {
                            tr[j, l+1] += tr[j, l];
                            tr[j, l+1] %= mod;
                        }
                    }
                }
            }
            if(tr[h,w] <= 0)
            {
                continue;

            }
            if (max < tr[h, w])
            {
                ans = b;
                max = tr[h, w];
            }
        }
        Console.WriteLine(max);
        if(max != 0) {
            for(int i = 0; i < k; i++)
            {
                if (ans[i])
                {
                    Console.WriteLine(n[i]);
                }
            }
        }
    }
}

0