AtCoder Beginner Contest 007

Submission #1770083

Source codeソースコード

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;


class Iroha
{
    public Iroha() { }
    public static int Main()
    {
        new Iroha().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        long A = cin.nextLong();
        long B = cin.nextLong();
        Console.WriteLine(calc2(B) - calc2(A-1));
    }
    
    long calc2(long N)
    {
        string S = N.ToString();
        long[,] dp = new long[2, 2];
        dp[0, 1] = 1;
        for (int i = 0; i < S.Length; i++)
        {
            long[,] nextdp = new long[2, 2];
            int target = S[i] - '0';
            for (int k = 0; k < 2; k++)
            {
                for (int j = 0; j < 2; j++)
                {
                    if (dp[j, k] == 0) continue;

                    for (int l = 0; l < 10; l++)
                    {
                        if (k == 1 && l > target) continue;
                        int nextj = j;
                        int nextk = k;
                        if (l != target) nextk = 0;
                        if (l == 4 || l == 9) nextj = 1;
                        nextdp[nextj, nextk] += dp[j, k];
                    }
                }
            }
            dp = nextdp;
        }
        long ans = dp[1, 0] + dp[1, 1];
        return ans;
    }
    
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Submission

Task問題 D - 禁止された数字
User nameユーザ名 古寺いろは
Created time投稿日時
Language言語 C# (Mono 4.6.2.0)
Status状態 AC
Score得点 100
Source lengthソースコード長 2878 Byte
File nameファイル名
Exec time実行時間 22 ms
Memory usageメモリ使用量 13140 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt,subtask0_sample04.txt
Subtask1 30 / 30 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt
Subtask2 70 / 70 subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt,subtask0_sample04.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample01.txt AC 21 ms 11092 KB
subtask0_sample02.txt AC 21 ms 9044 KB
subtask0_sample03.txt AC 21 ms 11220 KB
subtask0_sample04.txt AC 21 ms 9172 KB
subtask1_01.txt AC 22 ms 13140 KB
subtask1_02.txt AC 21 ms 9172 KB
subtask1_03.txt AC 21 ms 11220 KB
subtask1_04.txt AC 21 ms 9172 KB
subtask1_05.txt AC 21 ms 11220 KB
subtask1_06.txt AC 21 ms 11092 KB
subtask1_07.txt AC 21 ms 11220 KB
subtask1_08.txt AC 21 ms 11092 KB
subtask1_09.txt AC 21 ms 9172 KB
subtask1_10.txt AC 20 ms 9172 KB
subtask1_11.txt AC 21 ms 11220 KB
subtask1_12.txt AC 21 ms 9172 KB
subtask1_13.txt AC 21 ms 11220 KB
subtask2_01.txt AC 20 ms 9172 KB
subtask2_02.txt AC 21 ms 11092 KB
subtask2_03.txt AC 21 ms 11220 KB
subtask2_04.txt AC 20 ms 9172 KB
subtask2_05.txt AC 21 ms 9044 KB
subtask2_06.txt AC 21 ms 9172 KB
subtask2_07.txt AC 21 ms 13140 KB
subtask2_08.txt AC 20 ms 11092 KB
subtask2_09.txt AC 21 ms 11220 KB
subtask2_10.txt AC 21 ms 11092 KB
subtask2_11.txt AC 20 ms 9172 KB
subtask2_12.txt AC 21 ms 11220 KB
subtask2_13.txt AC 20 ms 9172 KB
subtask2_14.txt AC 21 ms 9172 KB
subtask2_15.txt AC 21 ms 9172 KB
subtask2_16.txt AC 21 ms 9172 KB
subtask2_17.txt AC 22 ms 11092 KB
subtask2_18.txt AC 21 ms 11220 KB
subtask2_19.txt AC 21 ms 11220 KB
subtask2_20.txt AC 21 ms 11092 KB
subtask2_21.txt AC 21 ms 9044 KB
subtask2_22.txt AC 21 ms 11220 KB