Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define vi vector <int>
- #define mi vector <vector <int>>
- // Quick functions
- //#define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)(a.size())
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- #define EACH(e, a) for (auto& e : a)
- // Pragmas
- #ifndef TIOM4EG
- #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
- #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- #endif
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- using namespace __gnu_pbds;
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
- //#define int long long
- const int INF = 1e9 + 7, MD = 998244353, MOD = 1e9 + 7, LG = 30, B = 31, S = 512;
- int dpe[2600][10], dpo[2600][10], len[2600]; // 2k-1, 2k
- inline int add(int a, int b) { return a + b - MOD * (a + b >= MOD); }
- signed main() {
- FOR(i, 0, 10) dpo[1][i] = 1;
- FOR(i, 0, 5) dpe[1][i] = 1;
- FOR(i, 2, 2600) FOR(j, 0, 10) FOR(k, 0, 10 - j) dpo[i][j] = add(dpo[i][j], dpo[i - 1][k]), dpe[i][j] = add(dpe[i][j], dpe[i - 1][k]);
- len[1] = 9, len[2] = 13;
- FOR(i, 3, 2600) {
- len[i] = len[i - 1];
- if (i & 1) FOR(j, 1, 10) len[i] = add(len[i], dpo[i / 2 + 1][j]);
- else FOR(j, 1, 10) len[i] = add(len[i], dpe[i / 2][j]);
- }
- fastIO;
- int q; cin >> q;
- while (q--) {
- string s; cin >> s;
- int n = sz(s), res = len[n - 1], pr = 0, f = 0;
- if (n & 1) FOR(i, 0, n / 2 + 1) {
- FOR(j, !i, min(10 - pr, (i == n / 2 & !f) + s[i] - '0')) res = add(res, dpo[(n + 1) / 2 - i][j]);
- if (s[i] - '0' >= 10 - pr) break;
- if (s[i] > s[n - 1 - i]) f = 1;
- if (s[i] < s[n - 1 - i]) f = 0;
- pr = s[i] - '0';
- }
- else FOR(i, 0, n / 2) {
- if (i + 1 == n / 2) {
- if (s[i] < s[n - 1 - i]) FOR(j, !i, min(10 - pr, 1 + s[i] - '0')) res = add(res, dpe[n / 2 - i][j]);
- else if (s[i] == s[n - 1 - i]) FOR(j, !i, min(10 - pr, !f + s[i] - '0')) res = add(res, dpe[n / 2 - i][j]);
- else FOR(j, !i, min(10 - pr, s[i] - '0')) res = add(res, dpe[n / 2 - i][j]);
- break;
- }
- FOR(j, !i, min(10 - pr, s[i] - '0')) res = add(res, dpe[n / 2 - i][j]);
- if (s[i] - '0' >= 10 - pr) break;
- if (s[i] > s[n - 1 - i]) f = 1;
- if (s[i] < s[n - 1 - i]) f = 0;
- pr = s[i] - '0';
- }
- cout << res << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement