結果

問題 No.315 世界のなんとか3.5
ユーザー mamekin
提出日時 2015-12-20 13:24:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 2,093 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 98,664 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-17 12:10:45
合計ジャッジ時間 5,796 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
const int MOD = 1000000007;
int solve(const string& s, int p)
{
int n = s.size();
vector<vector<int> > dp(4, vector<int>(3, 0));
dp[0][0] = 1;
for(int i=0; i<n-5; ++i){
vector<vector<int> > nextDp(4, vector<int>(3, 0));
for(int a=0; a<4; ++a){
for(int b=0; b<3; ++b){
for(int x=0; x<=9; ++x){
if(!(a & 2) && x > s[i] - '0')
continue;
int a2 = a;
if(x == 3)
a2 |= 1;
if(x < s[i] - '0')
a2 |= 2;
int b2 = (b + x) % 3;
nextDp[a2][b2] += dp[a][b];
nextDp[a2][b2] %= MOD;
}
}
}
dp.swap(nextDp);
}
int y = stoi(s.substr(max(0, n - 5)));
int ans = 0;
for(int a=0; a<4; ++a){
for(int b=0; b<3; ++b){
for(int x=0; x<100000; ++x){
if(!(a & 2) && x > y)
continue;
bool isUse3 = a & 1;
if(to_string(x).find('3') != string::npos)
isUse3 = true;
int b2 = (b + x) % 3;
if((isUse3 || b2 == 0) && x % p != 0){
ans += dp[a][b];
ans %= MOD;
}
}
}
}
return ans;
}
int main()
{
string a, b;
int p;
cin >> a >> b >> p;
int i = a.size() - 1;
while(a[i] == '0'){
a[i] = '9';
-- i;
}
-- a[i];
int ans = solve(b, p) - solve(a, p);
ans %= MOD;
ans += MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0