QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760077#7954. Special NumbersLittlePantsWA 1ms3660kbC++143.4kb2024-11-18 14:38:002024-11-18 14:38:00

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 14:38:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3660kb
  • [2024-11-18 14:38:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define X first
#define Y second
#define F first
#define S second
#define vi vector<int>
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(ALL(x), v)
#define ub(x, v) upper_bound(ALL(x), v)
#define re(x) reverse(ALL(x))
#define uni(x) x.resize(unique(ALL(x)) - x.begin())
#define inf 1000000000
#define INF 1000000000000000000
#define mod 1000000007
#define MOD 998244353
#define get_bit(x, y) ((x>>y)&1)
#define mkp make_pair
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cerr << a << ' ', abc(b...);
}
#ifdef debug
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

template<class T> bool ckmin(T& a, const T& b) { return b<a ? a=b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a<b ? a=b, 1 : 0; }


const vector<int> prime = {2, 3, 5, 7};
vector<vector<int>> states;
map<pii, ll> dp;
vector<int> fac;
ll goal;

ll myhash(const vector<int> &v) {
  ll res = 0;
  if (v[4] == 1) return -1;
  for (int i = 0; i < 4; i++) {
    res = res * 100 + v[i];
  }
  return res;
}

vector<int> decode(ll hsh) {
  vector<int> v;
  if (hsh == -1) return vector<int>({0, 0, 0, 0, 1});
  for (int i = 0; i < 4; i++) {
    v.eb(hsh % 100);
    hsh /= 100;
  }
  reverse(ALL(v));
  v.eb(0);
  return v;
}

vector<int> add_fac(const vector<int> &cur_fac, int x) {
  vector<int> res(5);
  if (x == 0 || cur_fac[4] == 1) {
    res[4] = 1;
    return res;
  }
  for (int i = 0; i < 4; i++) {
    int j = prime[i], cnt = 0;
    while (x % j == 0) { 
      x /= j;
      cnt++;
    }
    res[i] = min(fac[i], cur_fac[i] + cnt);
  }
  return res;
}

ll dfs(int pos, int hsh, bool lim, bool lead, const vector<int> &num) {
  if (pos == -1) return hsh == goal || hsh == -1;
  if (!lim && !lead && dp.find(mkp(pos, hsh)) != dp.end()) return dp[mkp(pos, hsh)];
  int ub = (lim ? num[pos] : 9);
  vector<int> cur_fac = decode(hsh);
  ll res = 0;
  for (int i = 0; i <= ub; i++) {
    auto nxt = add_fac(cur_fac, i);
    if (i == 0 && lead) {
      res = (res + dfs(pos - 1, myhash(cur_fac), lim && i == ub, 1, num)) % mod;
    } else {
      res = (res + dfs(pos - 1, myhash(nxt), lim && i == ub, 0, num)) % mod;
    }
  }
  if (!lim && !lead) dp[mkp(pos, hsh)] = res;
  return res;
}

ll cal(ll x) {
  vector<int> num;
  int dig_cnt = 0;
  while (x) {
    num.eb(x % 10);
    x /= 10;
    dig_cnt++;
  }
  test(dig_cnt);
  return dfs(dig_cnt - 1, 0, 1, 1, num);
}

void get_allstates(int pos, vector<int> cur = {}) {
  if (pos == 4) {
    states.eb(cur);
    return;
  }
  for (int i = 0; i <= fac[pos]; i++) {
    cur.eb(i);
    get_allstates(pos + 1, cur);
    cur.pop_back();
  }
}

inline void solve() {
  ll k, l, r;
  cin >> k >> l >> r;

  fac.resize(4);
  for (int i = 0; i < 4; i++) {
    int j = prime[i];
    while (k % j == 0) {
      k /= j;
      fac[i]++;
    }
  }
  goal = myhash(fac);
  //get_allstates(0);
  test(SZ(states));
  test(cal(r));
  test(cal(l - 1));
  cout << cal(r) - cal(l - 1);
}

signed main() {
	IO;	
  solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

10 800 43021

output:

23570

result:

ok single line: '23570'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3600kb

input:

1125899906842624 1 100000000000000000000

output:

566570801

result:

wrong answer 1st lines differ - expected: '555058180', found: '566570801'