結果
| 問題 |
No.260 世界のなんとか3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-17 18:28:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 241 ms / 2,000 ms |
| コード長 | 925 bytes |
| コンパイル時間 | 3,340 ms |
| コンパイル使用メモリ | 290,876 KB |
| 実行使用メモリ | 40,600 KB |
| 最終ジャッジ日時 | 2025-08-17 18:28:13 |
| 合計ジャッジ時間 | 7,860 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::static_modint<7+(int)1e9>;
using ll = long long;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
auto solve = [](const string& S) {
int N = S.size();
vector dp(N + 1, vector(3, vector(8, vector(2, vector<mint>(2)))));
dp[0][0][0][0][0] = 1;
for(int i=0;i<N;i++)for(int r3=0;r3<3;r3++)for(int r8=0;r8<8;r8++)for(int has3=0;has3<2;has3++)for(int less=0;less<2;less++){
int lim=less?9:S[i]-'0';
for(int d=0;d<=lim;d++){
dp[i+1][(r3+d)%3][(2*r8+d)%8][has3||d==3][less||(d<lim)]+=dp[i][r3][r8][has3][less];
}
}
return dp[N];
};
string A,B;
cin>>A>>B;
auto dpA=solve(A);
auto dpB=solve(B);
mint ans=0;
for(int i=0;i<3;i++)for(int j=0;j<2;j++)for(int k=1;k<8;k++)if(i==0||j==1){
for(int l=0;l<2;l++)ans+=dpB[i][k][j][l];
ans-=dpA[i][k][j][1];
}
cout<<ans.val()<<"\n";
}