結果

問題 No.315 世界のなんとか3.5
ユーザー koyumeishikoyumeishi
提出日時 2015-12-01 03:44:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,677 ms / 2,000 ms
コード長 2,472 bytes
コンパイル時間 3,814 ms
コンパイル使用メモリ 106,908 KB
実行使用メモリ 23,024 KB
最終ジャッジ日時 2023-10-12 07:13:17
合計ジャッジ時間 23,626 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
22,804 KB
testcase_01 AC 59 ms
18,792 KB
testcase_02 AC 81 ms
20,820 KB
testcase_03 AC 59 ms
22,668 KB
testcase_04 AC 60 ms
18,768 KB
testcase_05 AC 61 ms
20,676 KB
testcase_06 AC 83 ms
22,712 KB
testcase_07 AC 61 ms
22,808 KB
testcase_08 AC 61 ms
22,656 KB
testcase_09 AC 60 ms
22,832 KB
testcase_10 AC 60 ms
22,648 KB
testcase_11 AC 59 ms
20,812 KB
testcase_12 AC 385 ms
18,972 KB
testcase_13 AC 384 ms
21,092 KB
testcase_14 AC 711 ms
21,628 KB
testcase_15 AC 713 ms
21,744 KB
testcase_16 AC 714 ms
21,716 KB
testcase_17 AC 714 ms
21,776 KB
testcase_18 AC 390 ms
21,020 KB
testcase_19 AC 391 ms
21,136 KB
testcase_20 AC 411 ms
23,024 KB
testcase_21 AC 413 ms
21,080 KB
testcase_22 AC 729 ms
21,668 KB
testcase_23 AC 736 ms
21,672 KB
testcase_24 AC 718 ms
21,708 KB
testcase_25 AC 733 ms
21,648 KB
testcase_26 AC 711 ms
21,564 KB
testcase_27 AC 705 ms
21,812 KB
testcase_28 AC 717 ms
21,676 KB
testcase_29 AC 1,219 ms
22,880 KB
testcase_30 AC 1,202 ms
22,876 KB
testcase_31 AC 1,204 ms
22,876 KB
testcase_32 AC 1,385 ms
22,832 KB
testcase_33 AC 744 ms
21,692 KB
testcase_34 AC 1,062 ms
20,992 KB
testcase_35 AC 1,677 ms
22,916 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.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Solver
{
	private const long MOD = 1000000007;

	private long calc(String n, int p){
		long[,,] dp = new long[2,800,2*4*2];
		int u = 0;
		int v = 1;
		dp[0,0,0] = 1;

		for(int i=0; i<n.Length; i++){
			int k = ((int)n[i]) - ((int)'0');
			if(i<n.Length-5){
				for(int a=0;a<2;a++){
				for(int b=0;b<3;b++){
				for(int c=0;c<2;c++){
					int s = (a<<3)|(b<<1)|c;
					dp[v,0,s] = 0;
				}}}

				for(int a=0;a<2;a++){
				for(int b=0;b<3;b++){
				for(int c=0;c<2;c++){
					int s = (a<<3)|(b<<1)|c;
					for(int d=0;d<10;d++){
						if(a==0 && d>k){
							continue;
						}
						int a_ = a|(d<k?1:0);
						int b_ = (b+d)%3;
						int c_ = c|(d==3?1:0);
						int s_ = (a_<<3)|(b_<<1)|c_;

						dp[v,0,s_] += dp[u,0,s];
						if(dp[v,0,s_] >= MOD) dp[v,0,s_] -= MOD;
					}
				}}}
			}
			else{
				for(int j=0;j<p;j++){
				for(int a=0;a<2;a++){
				for(int b=0;b<3;b++){
				for(int c=0;c<2;c++){
					int s = (a<<3)|(b<<1)|c;
					dp[v,j,s] = 0;
				}}}}

				for(int j=0;j<p;j++){
				for(int a=0;a<2;a++){
				for(int b=0;b<3;b++){
				for(int c=0;c<2;c++){
					int s = (a<<3)|(b<<1)|c;
					for(int d=0;d<10;d++){
						if(a==0 && d>k){
							continue;
						}
						int a_ = a|(d<k?1:0);
						int b_ = (b+d)%3;
						int c_ = c|(d==3?1:0);
						int s_ = (a_<<3)|(b_<<1)|c_;
						int j_ = (j*10 + d) % p;
						dp[v,j_,s_] += dp[u,j,s];
						if(dp[v,j_,s_] >= MOD) dp[v,j_,s_] -= MOD;
					}
				}}}}
			}
			u ^= 1;
			v ^= 1;
		}

		long ret = 0;

		for(int j=1;j<p;j++){
		for(int a=0;a<2;a++){
		for(int b=0;b<3;b++){
		for(int c=0;c<2;c++){
			if(c==0 && b!=0){
				continue;
			}
			int s = (a<<3)|(b<<1)|c;
			ret += dp[u,j,s];
			if(ret>=MOD) ret -= MOD;
		}}}}

		return ret;
	}
    public void Solve()
    {
        String[] input = Console.ReadLine().Split();
        int p = int.Parse(input[2]);
        long ans = calc(input[1], p);
        ans = (ans - calc(input[0], p) + MOD) % MOD;

        int b=0;
        int c=0;
        int d=0;
        for(int i=0;i<input[0].Length; i++){
			int k = ((int)input[0][i]) - ((int)'0');
			b = (b+k)%3;
			c = c|(k==3?1:0);
			d = (d*10+k)%p;
        }
        if((b==0 || c==1) && d != 0){
        	ans = (ans+1)%MOD;
        }

        Console.WriteLine(ans);

    }
    static int Main()
    {
        var solver = new Solver();
        solver.Solve();
        return 0;
    }
}
0