結果
| 問題 | No.260 世界のなんとか3 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-09 22:16:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,080 bytes |
| 記録 | |
| コンパイル時間 | 1,112 ms |
| コンパイル使用メモリ | 111,344 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-22 00:25:38 |
| 合計ジャッジ時間 | 3,908 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 17 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#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>
#include <iterator>
using namespace std;
const int MOD = 1000000007;
int encode(int a, int b, int c, int d)
{
return ((a * 2 + b) * 3 + c) * 8 + d;
}
tuple<int, int, int, int> decode(int x)
{
tuple<int, int, int, int> ans;
get<3>(ans) = x % 8;
x /= 8;
get<2>(ans) = x % 3;
x /= 3;
get<1>(ans) = x % 2;
x /= 2;
get<0>(ans) = x;
return ans;
}
int solve(const string& s)
{
int n = s.size();
vector<int> dp(96, 0);
dp[encode(1, 0, 0, 0)] = 1;
for(int i=0; i<n; ++i){
vector<int> nextDp(96, 0);
for(int x=0; x<96; ++x){
int a, b, c, d;
tie(a, b, c, d) = decode(x);
for(int j=0; j<=9; ++j){
if(a == 1 && s[i] - '0' < j)
continue;
int a2 = (a == 1 && s[i] - '0' == j) ? 1 : 0;
int b2 = (b == 1 || j == 3) ? 1 : 0;
int c2 = (c * 10 + j) % 3;
int d2 = (d * 10 + j) % 8;
int y = encode(a2, b2, c2, d2);
nextDp[y] += dp[x];
nextDp[y] %= MOD;
}
}
dp.swap(nextDp);
}
int ans = 0;
for(int x=0; x<96; ++x){
int a, b, c, d;
tie(a, b, c, d) = decode(x);
if((b == 1 || c == 0) && d != 0)
ans += dp[x];
}
return ans;
}
int main()
{
string a, b;
cin >> a >> b;
unsigned i = a.find_last_not_of('0');
-- a[i];
while(++ i < a.size())
a[i] = '9';
if(a[0] == '0')
a = a.substr(1);
int ans = solve(b) - solve(a);
ans %= MOD;
ans += MOD;
ans %= MOD;
cout << ans << endl;
return 0;
}