# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921991 | 2024-02-04T16:03:36 Z | dwuy | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 3 ms | 600 KB |
#include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) int32_t(s.length()) #define MASK(k)(1LL<<(k)) #define TASK "test" #define int long long using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; int dp[20][10][11]; string ts(int x){ stringstream ss; ss << x; string res; ss >> res; return res; } bool ok(string s){ for(int i=0; i+1<len(s); i++) if(s[i] == s[i+1]) return 0; for(int i=1; i+1<len(s); i++) if(s[i+1] == s[i-1]) return 0; return 1; } int calc(int x){ memset(dp, 0, sizeof dp); string s = ts(x); reverse(s.begin(), s.end()); for(int j=0; j<=9; j++) dp[1][j][10] = 1; for(int i=2; i<=len(s); i++){ for(int j=0; j<10; j++){ for(int k=0; k<10; k++){ if(j == k) continue; for(int f=0; f<=10; f++){ if(j == f) continue; dp[i][j][k] += dp[i-1][k][f]; } } } } int res = 0; for(int i=1; i<len(s); i++){ for(int j=1; j<=9; j++){ for(int k=0; k<=10; k++){ res += dp[i][j][k]; } } } cerr << res << endl; for(int i=len(s); i>0 ; i--){ for(int j=(i==len(s)? 1 : 0); j<s[i-1]-'0'; j++){ if(i<len(s) && j == s[i] - '0') continue; if(i+1<len(s) && j == s[i+1] - '0') continue; for(int k=0; k<=10; k++){ if(i<len(s) && k == s[i] -'0') continue; res += dp[i][j][k]; } } } return res + ok(s); } int32_t main(){ fastIO; file(TASK); int l, r; cin >> l >> r; cout << calc(r) - calc(l-1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Incorrect | 2 ms | 348 KB | Output isn't correct |
3 | Incorrect | 2 ms | 348 KB | Output isn't correct |
4 | Incorrect | 2 ms | 348 KB | Output isn't correct |
5 | Incorrect | 2 ms | 348 KB | Output isn't correct |
6 | Incorrect | 2 ms | 348 KB | Output isn't correct |
7 | Incorrect | 2 ms | 348 KB | Output isn't correct |
8 | Incorrect | 2 ms | 344 KB | Output isn't correct |
9 | Incorrect | 2 ms | 348 KB | Output isn't correct |
10 | Incorrect | 1 ms | 348 KB | Output isn't correct |
11 | Incorrect | 2 ms | 348 KB | Output isn't correct |
12 | Incorrect | 1 ms | 348 KB | Output isn't correct |
13 | Incorrect | 2 ms | 348 KB | Output isn't correct |
14 | Incorrect | 3 ms | 348 KB | Output isn't correct |
15 | Incorrect | 2 ms | 348 KB | Output isn't correct |
16 | Incorrect | 3 ms | 348 KB | Output isn't correct |
17 | Incorrect | 1 ms | 348 KB | Output isn't correct |
18 | Incorrect | 2 ms | 348 KB | Output isn't correct |
19 | Incorrect | 2 ms | 348 KB | Output isn't correct |
20 | Incorrect | 2 ms | 348 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Incorrect | 2 ms | 348 KB | Output isn't correct |
4 | Incorrect | 3 ms | 348 KB | Output isn't correct |
5 | Incorrect | 2 ms | 348 KB | Output isn't correct |
6 | Incorrect | 2 ms | 348 KB | Output isn't correct |
7 | Incorrect | 2 ms | 348 KB | Output isn't correct |
8 | Incorrect | 2 ms | 348 KB | Output isn't correct |
9 | Incorrect | 2 ms | 348 KB | Output isn't correct |
10 | Incorrect | 2 ms | 348 KB | Output isn't correct |
11 | Incorrect | 2 ms | 348 KB | Output isn't correct |
12 | Incorrect | 2 ms | 348 KB | Output isn't correct |
13 | Incorrect | 2 ms | 348 KB | Output isn't correct |
14 | Incorrect | 2 ms | 348 KB | Output isn't correct |
15 | Incorrect | 2 ms | 348 KB | Output isn't correct |
16 | Incorrect | 2 ms | 348 KB | Output isn't correct |
17 | Incorrect | 2 ms | 348 KB | Output isn't correct |
18 | Incorrect | 2 ms | 348 KB | Output isn't correct |
19 | Incorrect | 1 ms | 348 KB | Output isn't correct |
20 | Incorrect | 2 ms | 348 KB | Output isn't correct |
21 | Incorrect | 2 ms | 348 KB | Output isn't correct |
22 | Incorrect | 2 ms | 348 KB | Output isn't correct |
23 | Incorrect | 2 ms | 348 KB | Output isn't correct |
24 | Incorrect | 1 ms | 348 KB | Output isn't correct |
25 | Incorrect | 2 ms | 348 KB | Output isn't correct |
26 | Incorrect | 2 ms | 348 KB | Output isn't correct |
27 | Incorrect | 2 ms | 348 KB | Output isn't correct |
28 | Incorrect | 2 ms | 348 KB | Output isn't correct |
29 | Incorrect | 2 ms | 348 KB | Output isn't correct |
30 | Incorrect | 3 ms | 348 KB | Output isn't correct |
31 | Incorrect | 2 ms | 348 KB | Output isn't correct |
32 | Incorrect | 2 ms | 348 KB | Output isn't correct |
33 | Incorrect | 1 ms | 348 KB | Output isn't correct |
34 | Incorrect | 2 ms | 348 KB | Output isn't correct |
35 | Incorrect | 2 ms | 348 KB | Output isn't correct |
36 | Incorrect | 2 ms | 456 KB | Output isn't correct |
37 | Incorrect | 2 ms | 348 KB | Output isn't correct |
38 | Incorrect | 2 ms | 348 KB | Output isn't correct |
39 | Incorrect | 1 ms | 348 KB | Output isn't correct |
40 | Incorrect | 1 ms | 348 KB | Output isn't correct |
41 | Incorrect | 2 ms | 600 KB | Output isn't correct |
42 | Incorrect | 2 ms | 348 KB | Output isn't correct |
43 | Incorrect | 2 ms | 348 KB | Output isn't correct |
44 | Incorrect | 2 ms | 348 KB | Output isn't correct |
45 | Incorrect | 2 ms | 600 KB | Output isn't correct |