CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Numerot
Sender:ollpu
Submission time:2020-10-16 23:18:14 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.02 s2, 3details
#3--3details

Code

#include <bits/stdc++.h>
using namespace std;
// dp[prefix][pow][digit][-x] = (kesto, -x')
long dpv[10][19][10][10];
int dpo[10][19][10][10];
using UL = unsigned long;
UL p10[19];
const UL INF = 1e19;
pair<long, int> comp(int pref, UL v, int co) {
  long cst = 0;
  int vd[19];
  for (int j = 0; j < 19; ++j) {
    vd[j] = v%10;
    v /= 10;
  }
  for (int j = 0; j < 19; ++j) {
    if (!vd[j]) continue;
    int tpref = pref;
    for (int k = j+1; k < 19; ++k) {
      tpref = max(tpref, vd[k]);
    }
    cst += dpv[tpref][j][vd[j]][co];
    co = dpo[tpref][j][vd[j]][co];
  }
  return {cst, co};
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  p10[0] = 1;
  for (int i = 1; i < 19; ++i) p10[i] = p10[i-1]*10;
  for (int pw = 0; pw < 19; ++pw) {
    for (int dg = 1; dg < 10; ++dg) {
      for (int pref = 0; pref < 10; ++pref) {
        for (int mx = 0; mx < 10; ++mx) {
          UL v = p10[pw]*dg - mx;
          long cst = 0;
          auto cdone = [&]() {
            if (v == 0 || v > INF) {
              dpv[pref][pw][dg][mx] = cst;
              dpo[pref][pw][dg][mx] = int(v);
              return true;
            }
            return false;
          };
          if (cdone()) continue;
          if (!mx) v -= max(pref, dg), cst++;
          if (cdone()) continue;
          auto p = comp(pref, v, 0);
          p.first += cst;
          tie(dpv[pref][pw][dg][mx], dpo[pref][pw][dg][mx]) = p;
        }
      }
    }
  }
  int T;
  cin >> T;
  for (int Ti = 0; Ti < T; ++Ti) {
    long x;
    cin >> x;
    UL res = 0;
    for (UL jmp = INF/10; jmp; jmp /= 10) {
      while (comp(0, res+jmp, 0).first < x) res += jmp;
    }
    cout << res+1 << endl;
  }
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
1000
1
2
3
4
...

correct output
1
10
11
20
22
...

user output
1
10
11
20
22
...

Test 2

Group: 2, 3

Verdict:

input
1000
224995
413660
249827
2125
...

correct output
1731724
3216040
1940719
14585
532612
...

user output
4023114
7529811
4484340
32940
1267220
...

Test 3

Group: 3

Verdict:

input
1000
627887018110416188
785474884983906653
653772166720939773
784335285960673683
...

correct output
5530371754830260284
6918696171534226533
5757755627065159149
6908439780325129803
3223801064342340738
...

user output
(empty)