Submission #362165

#TimeUsernameProblemLanguageResultExecution timeMemory
362165HehehePalindrome-Free Numbers (BOI13_numbers)C++14
73.75 / 100
1 ms632 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long LL; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<int, int> #define sz(x) (int)((x).size()) #define int long long /* #define cin in #define cout out ifstream in(".in"); ofstream out(".out"); */ const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const LL inf = 2e9; const LL mod = 1e9 + 7; const int N = 2e2 + 11; const LL INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); int n, a[N], dp[30][30][30][2][2], M, d; int get(string s1, string s2, int M, int d){ n = sz(s2); while(sz(s1) < sz(s2))s1 = '0' + s1; s1 = '.' + s1; s2 = '.' + s2; //cout << s1 << '\n'; //cout << s2 << '\n'; dp[0][0][0][0][0] = 1; int ans = 0; for(int i = 1; i <= n; i++){ int x = s1[i] - '0', y = s2[i] - '0'; //cout << "pos = " << i << '\n'; for(int smaller = 0; smaller <= 1; smaller++){ for(int bigger = 0; bigger <= 1; bigger++){ for(int A = 0; A <= 9; A++){ for(int B = 0; B <= 9; B++){ for(int C = 0; C <= 9; C++){ if(!smaller && C > y)continue; if(!bigger && C < x)continue; if((i >= 3) && ((C == B) || (A == C) || (B == C)))continue; if((i >= 2) && (B == C))continue; //if(dp[i - 1][A][B][smaller][bigger])cout << A << ' ' << B << ' ' << C << '\n'; int smaller1 = smaller, bigger1 = bigger; if(C < y)smaller1 = 1; if(C > x)bigger1 = 1; dp[i][B][C][smaller1][bigger1] += dp[i - 1][A][B][smaller][bigger]; } } } } } } for(int A = 0; A <= 9; A++){ for(int B = 0; B <= 9; B++){ for(int smaller = 0; smaller <= 1; smaller++){ for(int bigger = 0; bigger <= 1; bigger++){ ans += dp[n][A][B][smaller][bigger]; } } } } return ans; } void solve(){ string s1, s2; cin >> s1 >> s2; int ans = get(s1, s2, M, d); cout << ans << '\n'; } int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); //cout << setptecision(6) << fixed; int T = 1; //cin >> T; while(T--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...