답안 #263054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263054 2020-08-13T12:38:22 Z Valera_Grinenko Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
1 ms 384 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll dp[20][10][10][2]; //pos, prev1, prev2, (less?)
ll solve(string s, bool l) {
  int n = s.size();
  for(int i = 0; i <= n; i++)
    for(int a = 0; a < 10; a++)
      for(int b = 0; b < 10; b++)
        dp[i][a][b][0] = dp[i][a][b][1] = 0;
  for(int i = 0; i < n; i++) {
    if(i == 0) {
      for(int a = 0; a <= s[0] - '0'; a++)
        dp[i + 1][a][0][a != (s[0] - '0')]++;
      continue;
    }
    if(i == 1) {
      for(int a = 0; a < 10; a++)
        for(int b = 0; b < 10; b++) {
          if(a == b) continue;
          if(a <= (s[i] - '0'))
            dp[i + 1][a][b][a < (s[i] - '0')] += dp[i][b][0][0];
          dp[i + 1][a][b][1] += dp[i][b][0][1];
        }
      continue;
    }
    for(int a = 0; a < 10; a++)
      for(int b = 0; b < 10; b++)
        for(int c = 0; c < 10; c++)
          if(a != b && a != c && b != c) {
            if(a <= (s[i] - '0'))
              dp[i + 1][a][b][a < (s[i] - '0')] += dp[i][b][c][0];
            dp[i + 1][a][b][1] += dp[i][b][c][1];
          }
  }

  ll ans = 0;
  for(int i = 0; i < 10; i++)
    for(int j = 0; j < 10; j++)
      ans += dp[n][i][j][1];
  if(l) {
    for(int i = 0; i < 10; i++)
      for(int j = 0; j < 10; j++)
        ans += dp[n][i][j][0];
  }
  return ans;
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  string a, b;

  cin >> a >> b;

  cout << solve(b, 1) - solve(a, 0);

  return 0;
}
/*

*/

Compilation message

numbers.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Incorrect 1 ms 384 KB Output isn't correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Incorrect 0 ms 384 KB Output isn't correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Correct 1 ms 384 KB Output is correct
7 Incorrect 1 ms 384 KB Output isn't correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Correct 1 ms 384 KB Output is correct
12 Incorrect 1 ms 384 KB Output isn't correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Incorrect 1 ms 384 KB Output isn't correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct