結果
| 問題 | No.260 世界のなんとか3 |
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2017-01-01 19:45:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 85 ms / 2,000 ms |
| コード長 | 1,686 bytes |
| 記録 | |
| コンパイル時間 | 825 ms |
| コンパイル使用メモリ | 93,056 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-12-16 04:59:06 |
| 合計ジャッジ時間 | 2,777 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second
#define INF 2147483600
#define MOD 1000000007
#define long long long
long dp[10005][2][2][3][8];
// [上から何桁][EQ?][3を使った][mod3][mod8]
long solve(string &s){
fill(dp[0][0][0][0], dp[10002][0][0][0], 0);
dp[0][1][0][0][0]=1;
int n = s.size();
rep(i,n) rep(j,2) rep(k,3) rep(l,8){
rep(m,10) (dp[i+1][0][j|(m==3)][(k*10+m)%3][(l*10+m)%8] += dp[i][0][j][k][l]) %= MOD;
int mx = s[i]-'0';
rep(m,mx+1) (dp[i+1][m==mx][j|(m==3)][(k*10+m)%3][(l*10+m)%8] += dp[i][1][j][k][l]) %= MOD;
}
long ret = 0;
rep(i,2){
rep(j,3)rep(k,8) if(k!=0) ret = (ret+dp[n][i][1][j][k])%MOD; // 3を使った
rep(k,8) if(k!=0) ret = (ret+dp[n][i][0][0][k])%MOD; // 3を使わずmod3=0
}
return ret;
}
bool count(string &s){
int n = s.size();
int acc=0;
rep(i,n) acc = (acc*10+s[i]-'0')%8;
if(acc%8==0) return false;
rep(i,n) if(s[i]=='3') return true;
acc=0;
rep(i,n) acc = (acc*10+s[i]-'0')%3;
if(acc%3==0) return true;
return false;
}
int main(){
string a,b;
cin>>a>>b;
long ans = solve(b) - solve(a);
if(count(a)) ans++;
cout << (ans+MOD)%MOD << endl;
return 0;
}
tossy