結果
| 問題 |
No.260 世界のなんとか3
|
| コンテスト | |
| ユーザー |
Kmcode1
|
| 提出日時 | 2015-07-31 22:42:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 2,000 ms |
| コード長 | 1,604 bytes |
| コンパイル時間 | 867 ms |
| コンパイル使用メモリ | 96,788 KB |
| 実行使用メモリ | 24,064 KB |
| 最終ジャッジ日時 | 2024-11-07 17:58:26 |
| 合計ジャッジ時間 | 3,066 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define MAX 10002
long long int dp[MAX][3][2][9][2][2]; //under upper
bool use[MAX][3][2][9][2][2]; //under upper
string a;
string b;
#define MOD 1000000007
inline long long int dfs(int c, int d, int e, int f, int g, int h){
if (c == a.size()){
bool ok = (d == 0);
ok |= e;
ok &= (bool)(f != 0);
return ok;
}
if (use[c][d][e][f][g][h]){
return dp[c][d][e][f][g][h];
}
use[c][d][e][f][g][h]=true;
long long int r = 0;
int wa = a[c] - '0';
int wb = b[c] - '0';
for (int i = 0; i < 10; i++){
if (wa > i&&g==false){
continue;
}
if (i > wb&&h == false){
continue;
}
r += dfs(c + 1, (d*10 + i) % 3, e | (i == 3),(f*10+i)%8,g | (wa<i), h | (wb>i));
r %= MOD;
}
dp[c][d][e][f][g][h] = r;
return r;
}
int main(){
cin >> a;
cin >> b;
int siz = max(a.size(), b.size());
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
while (a.size() != siz){
a.push_back('0');
}
while (b.size() != siz){
b.push_back('0');
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
long long int ans = dfs(0, 0, 0, 0, 0, 0);
printf("%lld\n", ans);
return 0;
}
Kmcode1