結果
問題 | No.260 世界のなんとか3 |
ユーザー | nomi |
提出日時 | 2019-02-16 16:57:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 3,909 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 174,336 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-09-22 14:13:04 |
合計ジャッジ時間 | 5,305 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 129 ms
18,560 KB |
testcase_04 | AC | 128 ms
18,560 KB |
testcase_05 | AC | 61 ms
8,960 KB |
testcase_06 | AC | 40 ms
7,040 KB |
testcase_07 | AC | 121 ms
16,384 KB |
testcase_08 | AC | 140 ms
16,512 KB |
testcase_09 | AC | 68 ms
9,856 KB |
testcase_10 | AC | 100 ms
15,104 KB |
testcase_11 | AC | 131 ms
17,152 KB |
testcase_12 | AC | 109 ms
14,080 KB |
testcase_13 | AC | 20 ms
6,944 KB |
testcase_14 | AC | 127 ms
16,384 KB |
testcase_15 | AC | 26 ms
6,940 KB |
testcase_16 | AC | 99 ms
13,824 KB |
testcase_17 | AC | 73 ms
11,136 KB |
testcase_18 | AC | 61 ms
10,240 KB |
testcase_19 | AC | 131 ms
16,384 KB |
testcase_20 | AC | 81 ms
11,520 KB |
testcase_21 | AC | 94 ms
12,416 KB |
testcase_22 | AC | 98 ms
14,208 KB |
testcase_23 | AC | 10 ms
6,940 KB |
testcase_24 | AC | 120 ms
15,232 KB |
testcase_25 | AC | 204 ms
18,560 KB |
testcase_26 | AC | 122 ms
18,560 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 123 ms
18,560 KB |
testcase_29 | AC | 122 ms
18,688 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int (i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl; #define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl; #define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } template<typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template<typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template<class T> void Add(T &a, const T &b, const T &mod=1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } // ------------------------------------------------------------------------------------------ string A, B; int dp[11111][2][2][2][3][8]; int a[111]; int rec(int digit, int over, int smaller, int three, int mod3, int mod8) { if (digit >= B.size()) { return (three || mod3 == 0) && (mod8 != 0); } if (dp[digit][over][smaller][three][mod3][mod8] != -1) { return dp[digit][over][smaller][three][mod3][mod8]; } int ue = (smaller ? 9 : B[digit] - '0'); int shita = (over ? 0 : A[digit] - '0'); int ret = 0; for (int num = shita; num <= ue; num++) { int t = rec(digit+1, over || (num > shita), smaller || (num < ue), three || (num == 3), (mod3+num)%3, (10*mod8+num)%8); Add(ret, t); } return dp[digit][over][smaller][three][mod3][mod8] = ret; } signed main() { cin >> A >> B; int diff = B.size() - A.size(); string zero = ""; rep (i, diff) { zero += "0"; } A = zero + A; // rep (i, 11111) rep (j, 2) rep (k, 2) rep (l, 2) rep (m, 3) rep (n, 8) dp[i][j][k][l][m][n] = -1; // int ans = rec(0, 0, 0, 0, 0, 0); dp[0][0][0][0][0][0] = 1; for (int digit = 0; digit < B.size(); digit++) { for (int over : {0, 1}) { for (int less : {0, 1}) { for (int three : {0, 1}) { for (int mod3 = 0; mod3 < 3; mod3++) { for (int mod8 = 0; mod8 < 8; mod8++) { int ue = (less ? 9 : B[digit] - '0'); int shita = (over ? 0 : A[digit] - '0'); for (int num = shita; num <= ue; num++) { Add(dp[digit+1][over || (num > shita)][less || (num < ue)][three || (num == 3)][(mod3+num)%3][(10*mod8+num)%8], dp[digit][over][less][three][mod3][mod8]); } } } } } } } int ans = 0; for (int over : {0, 1}) { for (int less : {0, 1}) { for (int three : {0, 1}) { for (int mod3 = 0; mod3 < 3; mod3++) { for (int mod8 = 0; mod8 < 8; mod8++) { if ((three || mod3 == 0) && (mod8 != 0)) { Add(ans, dp[B.size()][over][less][three][mod3][mod8]); } } } } } } cout << ans << endl; return 0; }