結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | eitaho |
提出日時 | 2015-12-08 01:30:54 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,726 bytes |
コンパイル時間 | 1,063 ms |
コンパイル使用メモリ | 119,048 KB |
実行使用メモリ | 61,780 KB |
最終ジャッジ日時 | 2024-09-14 19:00:00 |
合計ジャッジ時間 | 5,694 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
32,544 KB |
testcase_01 | AC | 39 ms
25,728 KB |
testcase_02 | AC | 39 ms
25,596 KB |
testcase_03 | AC | 40 ms
27,784 KB |
testcase_04 | AC | 39 ms
25,596 KB |
testcase_05 | AC | 39 ms
25,852 KB |
testcase_06 | AC | 47 ms
25,624 KB |
testcase_07 | AC | 40 ms
27,648 KB |
testcase_08 | AC | 39 ms
23,860 KB |
testcase_09 | AC | 38 ms
25,720 KB |
testcase_10 | AC | 40 ms
23,732 KB |
testcase_11 | AC | 39 ms
27,656 KB |
testcase_12 | AC | 237 ms
32,724 KB |
testcase_13 | AC | 236 ms
30,672 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
コンパイルメッセージ
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.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { static readonly int Mod = (int)1e9 + 7; void Add(ref int a, int b) { if ((a += b) >= Mod) a -= Mod; } public void Solve() { string A = Reader.String(), B = Reader.String(), C = Reader.String(); A = (BigInteger.Parse(A) - 1) + ""; Console.WriteLine((Count(B, C) - Count(A, C) + Mod) % Mod); } private int Count(string S, string C) { var A = S.Select(c => c - '0').ToArray(); int res = 0; int tail = S.Length - C.Length - 2; if (tail <= 0) { int N = int.Parse(S); int X = int.Parse(C); for (int i = 0; i <= N; i++) if ((i % 3 == 0 || (i + "").IndexOf('3') >= 0) && i % X != 0) res++; return res; } var dp = DP(A, tail); var dp1 = dp.Item1; var dp2 = dp.Item2; string sub = ""; for (int i = tail; i < tail + 3; i++) if (i >= 0) sub += S[i]; int to = int.Parse(sub); for (int mod = 0; mod < 3; mod++) for (int has3 = 0; has3 < 2; has3++) for (int less = 0; less < 2; less++) { if (mod == 0 || has3 == 1) Add(ref res, dp1[mod, has3, less]); for (int last = 0; last < 1000; last += 8) { if (last > to && less == 0) break; if ((mod + last) % 3 == 0 || has3 == 1 || (last + "").IndexOf('3') >= 0) res = (res + Mod - dp2[mod, has3, less]) % Mod; } } return res; } private Tuple<int[, ,], int[, ,]> DP(int[] A, int tail) { var dp = new int[3, 2, 2]; var res2 = new int[3, 2, 2]; dp[0, 0, 0] = 1; res2[0, 0, 0] = 1; for (int i = 0; i < A.Length; i++) { if (i == tail) res2 = (int[, ,])dp.Clone(); var nextdp = new int[3, 2, 2]; for (int mod = 0; mod < 3; mod++) for (int has3 = 0; has3 < 2; has3++) for (int less = 0; less < 2; less++) if (dp[mod, has3, less] > 0) for (int d = 0; d <= 9; d++) { if (less == 0 && d > A[i]) break; int nextmod = (mod + d) % 3; int nexthas3 = has3 | (d == 3 ? 1 : 0); int nextless = less | (d < A[i] ? 1 : 0); Add(ref nextdp[nextmod, nexthas3, nextless], dp[mod, has3, less]); } dp = nextdp; } return Tuple.Create(dp, res2); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }