結果

問題 No.612 Move on grid
ユーザー りあんりあん
提出日時 2017-11-23 17:05:46
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 256 ms / 2,500 ms
コード長 3,377 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 108,828 KB
実行使用メモリ 43,660 KB
最終ジャッジ日時 2023-08-22 22:09:19
合計ジャッジ時間 6,578 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
20,688 KB
testcase_01 AC 61 ms
20,704 KB
testcase_02 AC 61 ms
20,960 KB
testcase_03 AC 79 ms
30,976 KB
testcase_04 AC 126 ms
41,532 KB
testcase_05 AC 255 ms
41,600 KB
testcase_06 AC 253 ms
37,580 KB
testcase_07 AC 123 ms
43,660 KB
testcase_08 AC 256 ms
41,532 KB
testcase_09 AC 180 ms
39,732 KB
testcase_10 AC 141 ms
41,332 KB
testcase_11 AC 87 ms
35,440 KB
testcase_12 AC 178 ms
39,300 KB
testcase_13 AC 107 ms
41,344 KB
testcase_14 AC 211 ms
39,688 KB
testcase_15 AC 90 ms
34,300 KB
testcase_16 AC 235 ms
39,724 KB
testcase_17 AC 97 ms
41,324 KB
testcase_18 AC 209 ms
41,604 KB
testcase_19 AC 127 ms
37,256 KB
testcase_20 AC 153 ms
39,552 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.Generic;
using System.Linq;
using System.IO;

class Program
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();
    const int M = 1000000007;
    static void Main()
    {
        int t = sc.Int;
        if (t < 1 || 500 < t) throw new Exception();
        int a, b, c, d, e;
        sc.Multi(out a, out b, out c, out d, out e);
        if (a < -20 || 20 < a) throw new Exception();
        if (b < -20 || 20 < b) throw new Exception();
        if (c < -20 || 20 < c) throw new Exception();
        if (a == 0 && b == 0 && c == 0) throw new Exception();
        if (d > e || d < -10000 || e > 10000) throw new Exception();

        int m = 22000;
        var dp = new int[m];
        int s = 11000;
        dp[s] = 1;
        for (int i = 0; i < t; i++)
        {
            var next = new int[m];
            for (int j = 0; j < m; j++)
            {
                if (dp[j] > 0) {
                    next[j + a] = (next[j + a] + dp[j]) % M;
                    next[j - a] = (next[j - a] + dp[j]) % M;
                    next[j + b] = (next[j + b] + dp[j]) % M;
                    next[j - b] = (next[j - b] + dp[j]) % M;
                    next[j + c] = (next[j + c] + dp[j]) % M;
                    next[j - c] = (next[j - c] + dp[j]) % M;
                }
            }
            dp = next;
        }
        int ans = 0;
        for (int i = s + d; i <= s + e; i++)
            ans = (ans + dp[i]) % M;

        Prt(ans);
        sw.Flush();
    }
    static void Prt(string a) => sw.WriteLine(a);
    static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
    static void Prt(params object[] a) => Prt(string.Join(" ", a));
}

class Scan
{
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => Console.ReadLine().Trim();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries);
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
                       : eq<T, long>()   ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>()   ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); }
}
0