結果
| 問題 |
No.315 世界のなんとか3.5
|
| ユーザー |
|
| 提出日時 | 2015-12-20 13:22:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,045 bytes |
| コンパイル時間 | 884 ms |
| コンパイル使用メモリ | 97,144 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-17 12:00:37 |
| 合計ジャッジ時間 | 7,250 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 WA * 11 |
ソースコード
#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);
cout << ans << endl;
return 0;
}