답안 #564194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564194 2022-05-18T17:32:30 Z SSRS Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
long long solve(long long N){
  string S = to_string(N);
  int L = S.size();
  vector<vector<vector<vector<long long>>>> dp(L + 1, vector<vector<vector<long long>>>(2, vector<vector<long long>>(10, vector<long long>(10, 0))));
  dp[L][1][0][0] = 1;
  long long ans = 0;
  if (N > 0){
    ans++;
  }
  for (int i = L; i >= 0; i--){
    for (int j = 0; j < 2; j++){
      for (int k = 0; k < 10; k++){
        for (int l = 0; l < 10; l++){
          if (!(i == 0 && j == 1) && l > 0){
            ans += dp[i][j][k][l];
          }
          if (i > 0){
            for (int m = 0; m < 10; m++){
              bool ok = true;
              if (i < L && m == l){
                ok = false;
              }
              if (i < L - 1 && m == k){
                ok = false;
              }
              if (ok){
                int j2 = j;
                if (m > S[i - 1] - '0'){
                  j2 = 1;
                } else if (m < S[i - 1] - '0'){
                  j2 = 0;
                }
                dp[i - 1][j2][l][m] += dp[i][j][k][l];
              }
            }
          }
        }
      }
    }
  }
  return ans;
}
int main(){
  long long a, b;
  cin >> a >> b;
  cout << solve(b + 1) - solve(a) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 304 KB Output is correct
41 Correct 1 ms 292 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct