Submission #77607

# Submission time Handle Problem Language Result Execution time Memory
77607 2018-09-29T04:05:56 Z xiaowuc1 Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
3 ms 924 KB
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

ll dp[25][11][11][2];
bool seen[25][11][11][2];

ll solve(vector<int>& digits, int idx, int a, int b, int constrained) {
  if(seen[idx][a][b][constrained]) return dp[idx][a][b][constrained];
  seen[idx][a][b][constrained] = true;
  if(idx == digits.size()) {
    dp[idx][a][b][constrained] = 1;
    return 1;
  }
  for(int i = 0; i <= 9 && (i <= digits[idx] || !constrained); i++) {
    if(i == a || i == b) continue;
    int nc = constrained == 1 && i == digits[idx] ? 1 : 0;
    dp[idx][a][b][constrained] += solve(digits, idx+1, b, i, nc);
  }
  return dp[idx][a][b][constrained];
}

ll solve(ll n) {
  if(n < 0) return 0;
  vector<int> digits;
  while(n) {
    digits.push_back(n%10);
    n /= 10;
  }
  reverse(digits.begin(), digits.end());
  memset(dp, 0, sizeof(dp));
  memset(seen, 0, sizeof(seen));
  return solve(digits, 0, 10, 10, 1);
}

int main() {
  ll a, b;
  scanf("%lld %lld", &a, &b);
  printf("%lld\n", solve(b) - solve(a-1));
}

Compilation message

numbers.cpp: In function 'll solve(std::vector<int>&, int, int, int, int)':
numbers.cpp:27:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(idx == digits.size()) {
      ~~~~^~~~~~~~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 456 KB Output is correct
4 Incorrect 3 ms 476 KB Output isn't correct
5 Incorrect 2 ms 480 KB Output isn't correct
6 Incorrect 2 ms 544 KB Output isn't correct
7 Incorrect 2 ms 568 KB Output isn't correct
8 Incorrect 2 ms 588 KB Output isn't correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 668 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Incorrect 2 ms 676 KB Output isn't correct
15 Incorrect 2 ms 680 KB Output isn't correct
16 Correct 2 ms 704 KB Output is correct
17 Correct 2 ms 704 KB Output is correct
18 Correct 2 ms 788 KB Output is correct
19 Correct 2 ms 788 KB Output is correct
20 Incorrect 2 ms 788 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Incorrect 2 ms 788 KB Output isn't correct
6 Correct 2 ms 788 KB Output is correct
7 Incorrect 2 ms 788 KB Output isn't correct
8 Incorrect 2 ms 788 KB Output isn't correct
9 Incorrect 2 ms 788 KB Output isn't correct
10 Incorrect 2 ms 788 KB Output isn't correct
11 Correct 2 ms 788 KB Output is correct
12 Incorrect 2 ms 788 KB Output isn't correct
13 Incorrect 2 ms 848 KB Output isn't correct
14 Incorrect 2 ms 848 KB Output isn't correct
15 Incorrect 2 ms 848 KB Output isn't correct
16 Correct 2 ms 848 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 2 ms 848 KB Output is correct
20 Correct 2 ms 848 KB Output is correct
21 Correct 2 ms 848 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 2 ms 848 KB Output is correct
24 Correct 2 ms 848 KB Output is correct
25 Correct 2 ms 848 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 2 ms 848 KB Output is correct
28 Correct 2 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 3 ms 848 KB Output is correct
32 Correct 2 ms 924 KB Output is correct
33 Correct 3 ms 924 KB Output is correct
34 Correct 3 ms 924 KB Output is correct
35 Correct 3 ms 924 KB Output is correct
36 Correct 3 ms 924 KB Output is correct
37 Correct 3 ms 924 KB Output is correct
38 Correct 2 ms 924 KB Output is correct
39 Correct 2 ms 924 KB Output is correct
40 Correct 2 ms 924 KB Output is correct
41 Correct 2 ms 924 KB Output is correct
42 Correct 2 ms 924 KB Output is correct
43 Correct 2 ms 924 KB Output is correct
44 Correct 2 ms 924 KB Output is correct
45 Correct 2 ms 924 KB Output is correct