結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | koyumeishi |
提出日時 | 2015-12-01 04:11:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,670 ms / 2,000 ms |
コード長 | 2,581 bytes |
コンパイル時間 | 2,877 ms |
コンパイル使用メモリ | 104,940 KB |
実行使用メモリ | 24,964 KB |
最終ジャッジ日時 | 2023-10-12 07:15:57 |
合計ジャッジ時間 | 24,641 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
20,804 KB |
testcase_01 | AC | 58 ms
20,520 KB |
testcase_02 | AC | 77 ms
22,780 KB |
testcase_03 | AC | 58 ms
20,720 KB |
testcase_04 | AC | 58 ms
22,700 KB |
testcase_05 | AC | 60 ms
20,680 KB |
testcase_06 | AC | 82 ms
18,484 KB |
testcase_07 | AC | 60 ms
22,788 KB |
testcase_08 | AC | 60 ms
20,620 KB |
testcase_09 | AC | 57 ms
20,732 KB |
testcase_10 | AC | 58 ms
20,724 KB |
testcase_11 | AC | 58 ms
22,640 KB |
testcase_12 | AC | 384 ms
23,152 KB |
testcase_13 | AC | 385 ms
20,992 KB |
testcase_14 | AC | 711 ms
23,732 KB |
testcase_15 | AC | 712 ms
21,804 KB |
testcase_16 | AC | 715 ms
21,692 KB |
testcase_17 | AC | 713 ms
21,696 KB |
testcase_18 | AC | 391 ms
23,084 KB |
testcase_19 | AC | 391 ms
21,216 KB |
testcase_20 | AC | 414 ms
23,100 KB |
testcase_21 | AC | 414 ms
23,108 KB |
testcase_22 | AC | 736 ms
21,616 KB |
testcase_23 | AC | 736 ms
23,724 KB |
testcase_24 | AC | 714 ms
23,604 KB |
testcase_25 | AC | 734 ms
21,680 KB |
testcase_26 | AC | 711 ms
19,856 KB |
testcase_27 | AC | 710 ms
21,784 KB |
testcase_28 | AC | 718 ms
21,656 KB |
testcase_29 | AC | 1,235 ms
22,976 KB |
testcase_30 | AC | 1,218 ms
22,836 KB |
testcase_31 | AC | 1,212 ms
24,964 KB |
testcase_32 | AC | 1,388 ms
24,900 KB |
testcase_33 | AC | 742 ms
23,708 KB |
testcase_34 | AC | 1,090 ms
24,900 KB |
testcase_35 | AC | 1,670 ms
22,840 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; 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_ = 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; } }}} } 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_ = 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; } }}}} } 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(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; } }