結果

問題 No.315 世界のなんとか3.5
ユーザー koyumeishikoyumeishi
提出日時 2015-12-01 04:25:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,461 ms / 2,000 ms
コード長 2,333 bytes
コンパイル時間 3,177 ms
コンパイル使用メモリ 107,132 KB
実行使用メモリ 24,904 KB
最終ジャッジ日時 2023-10-12 07:18:41
合計ジャッジ時間 22,460 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,704 KB
testcase_01 AC 58 ms
20,888 KB
testcase_02 AC 82 ms
20,620 KB
testcase_03 AC 59 ms
20,656 KB
testcase_04 AC 59 ms
22,760 KB
testcase_05 AC 61 ms
20,600 KB
testcase_06 AC 84 ms
20,656 KB
testcase_07 AC 60 ms
22,780 KB
testcase_08 AC 60 ms
20,724 KB
testcase_09 AC 57 ms
22,780 KB
testcase_10 AC 59 ms
20,724 KB
testcase_11 AC 58 ms
20,664 KB
testcase_12 AC 344 ms
23,120 KB
testcase_13 AC 343 ms
23,116 KB
testcase_14 AC 627 ms
21,692 KB
testcase_15 AC 632 ms
23,632 KB
testcase_16 AC 629 ms
21,740 KB
testcase_17 AC 630 ms
23,632 KB
testcase_18 AC 348 ms
21,244 KB
testcase_19 AC 347 ms
23,088 KB
testcase_20 AC 368 ms
21,088 KB
testcase_21 AC 369 ms
21,000 KB
testcase_22 AC 648 ms
21,628 KB
testcase_23 AC 648 ms
23,740 KB
testcase_24 AC 628 ms
21,636 KB
testcase_25 AC 652 ms
23,712 KB
testcase_26 AC 628 ms
21,848 KB
testcase_27 AC 629 ms
21,820 KB
testcase_28 AC 636 ms
19,572 KB
testcase_29 AC 1,087 ms
22,824 KB
testcase_30 AC 1,064 ms
22,916 KB
testcase_31 AC 1,062 ms
24,836 KB
testcase_32 AC 1,216 ms
22,928 KB
testcase_33 AC 654 ms
21,760 KB
testcase_34 AC 952 ms
24,904 KB
testcase_35 AC 1,461 ms
24,884 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(ref String n, int p){
		long[,,] dp = new long[2,800,2*4*2];
		int u = 0;
		int v = 1;
		dp[0,0,0] = 1;
		int[] mooood3 = new int[12];
		for(int i=0; i<12; i++){
			mooood3[i] = i%3;
		}

		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;
					for(int d=0;d<10;d++){
						if(a==0 && d>k){
							continue;
						}
						int a_ = a|(d<k?1:0);
						int b_ = mooood3[(b+d)];
						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;
					}

					dp[u,0,s] = 0;

				}}}
			}
			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;
					for(int d=0;d<10;d++){
						if(a==0 && d>k){
							continue;
						}
						int a_ = a|(d<k?1:0);
						int b_ = mooood3[(b+d)];
						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;
					}

					dp[u,j,s] = 0;
				}}}}
			}
			u ^= 1;
			v ^= 1;
		}

		long ret = 0;

		for(int j=1;j<p;j++){
		for(int b=0;b<3;b++){
		for(int c=0;c<2;c++){
			if(c==0 && b!=0){
				continue;
			}
			for(int a=0;a<2;a++){
				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(ref input[1], p);
        ans = (ans - calc(ref 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