CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Numerot
Sender:PallomerenPiikki
Submission time:2020-10-18 12:51:29 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.28 s1, 2, 3details
#20.32 s2, 3details
#30.57 s3details

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

const int MAXDC = 20;
const int BASE = 10;

int pot[MAXDC+2];
pii dp[MAXDC][BASE][BASE][BASE];

struct Num {
  int val;
  Num(int x=0) : val(x) {}
  int operator[](int pos) const {
    return val / pot[pos] % 10;
  }
  int tzc() const {
    for (int i=2;; i++)
      if (val % pot[i] >= 10) return i-1;
  }
};

pii set_zeros(int k, int count) {
  int totsteps = 0;
  int totdec = 0;
  for (;;) {
    int rem = k % pot[count];
    if (rem < 10 && totsteps) break;
    if (k < 10) break;
    int zc = Num(k).tzc();
    int maxd = 0;
    for (int i=zc+1; i<MAXDC; i++)
      maxd = max(maxd, Num(k)[i]);
    int first = Num(k)[zc];
    int last = Num(k)[0];
    auto [steps, dec] = dp[zc][maxd][first][last];
    if (steps == 0) {
      steps = 1;
      dec = max(maxd, max(first, last));
    }
    totsteps += steps;
    totdec += dec;
    k -= dec;
  }
  return pii(totsteps, totdec);
}

int f(int k) {
  auto [steps, dec] = set_zeros(k, MAXDC);
  return steps + (k-dec>0);
}

int solve(int x) {
  int k = 0;
  int maxk = 1 + 9*x;
  if (x >= 1e6) {
    k = 8 * x;
  }
  for (int b=maxk; b >= 1; b /= 2) {
    while (k+b < maxk && f(k+b) < x) k += b;
  }
  while (f(k) < x) k++;
  return k;
}

void init() {
  pot[0] = 1;
  for (int i=1; i<MAXDC+2; i++)
    pot[i] = 10 * pot[i-1];
  for (int zc=1; zc<MAXDC; zc++) {
    for (int maxd=0; maxd<=9; maxd++) {
      for (int first=0; first<=9; first++) {
        for (int mod10=0; mod10<=9; mod10++) {
          int k = pot[zc+1]*maxd + pot[zc]*first + mod10;
          dp[zc][maxd][first][mod10] = set_zeros(k, zc);
        }
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(0);
  init();
  int t;
  cin >> t;
  t = min<int>(t, 100);
  while (t--) {
    int x;
    cin >> x;
    int k = solve(x);
    if (f(k) == x) {
      cout << k << '\n';
      cerr << fixed << 1.0*k/x << '\n';
    }
    else {
      cout << "-1\n";
    }
  }
}

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
...

Error:
1.000000
5.000000
3.666667
5.000000
4.400000
5.000000
4.714286
5.000000
4.888889
5.000000
5.000000
5.083333
5.384615
5.500000
5.666667
5.875000
5.882353
5.611111
5.789474
5.550000
5.714286
5.545455
5.652174
5.541667
5.600000
5.538462
5.555556
5.535714
5.551724
5.666667
5.709677
5.781250
5.878788
5.882353
5.771429
5.833333
5.729730
5.789474
5.692308
5.750000
5.682927
5.714286
5.674419
5.681818
5.666667
5.673913
5.744681
5.770833
5.816327
5.880000
5.882353
5.826923
5.849057
5.796296
5.818182
5.767857
5.789474
5.741379
5.762712
5.733333
5.737705
5.725806
5.730159
5.781250
5.800000
5.833333
5.880597
5.882353
5.855072
5.857143
5.830986
5.833333
5.808219
5.810811
5.786667
5.789474
5.766234
5.769231
5.759494
5.762500
5.802469
5.817073
5.843373
5.880952
5.882353
5.872093
5.862069
5.852273
5.842697
5.833333
5.824176
5.815217
5.806452
5.797872
5.789474
5.781250
5.783505
5.816327
5.828283
5.850000

Test 2

Group: 2, 3

Verdict:

input
1000
224995
413660
249827
2125
...

correct output
1731724
3216040
1940719
14585
532612
...

user output
1731724
3216040
1940719
14585
532612
...

Error:
7.696722
7.774597
7.768252
6.863529
7.459134
7.756069
7.791706
7.749322
7.781411
7.749224
7.571408
7.777786
7.491877
7.727819
7.668832
7.735237
7.791534
7.446121
7.795095
7.757758
7.766671
7.801649
7.787620
7.796840
7.854754
7.855501
7.666562
7.770122
7.838336
7.764845
6.943048
7.768104
7.798254
7.659750
7.837197
7.502591
7.790281
7.804266
7.753645
7.565357
7.758358
7.800845
7.799005
7.777212
7.729013
7.763953
7.757334
7.724528
7.800619
7.548720
7.804376
7.767593
7.851533
7.414885
7.797616
7.741325
7.511203
7.753564
7.481918
7.315499
7.427769
7.806145
7.805116
7.766925
7.841339
7.688229
7.861206
7.767965
7.798502
7.791620
7.774758
7.695902
7.767272
7.429428
7.756805
7.698562
7.769522
7.738075
7.780426
7.768435
7.769179
7.445724
7.776265
7.671489
7.477359
7.746091
7.448528
7.764801
7.797308
7.801113
7.804365
7.458486
7.802859
7.780100
7.746618
7.497334
7.742214
7.859817
7.851853
7.455834

Test 3

Group: 3

Verdict:

input
1000
627887018110416188
785474884983906653
653772166720939773
784335285960673683
...

correct output
5530371754830260284
6918696171534226533
5757755627065159149
6908439780325129803
3223801064342340738
...

user output
5530371754830260284
6918696171534226533
5757755627065159149
6908439780325129803
3223801064342340738
...

Error:
8.807909
8.808297
8.806976
8.808019
8.808453
8.807826
8.809676
8.809060
8.753368
8.809814
8.809966
8.809354
8.809551
8.809648
8.785603
8.810229
8.808563
8.803381
8.808326
8.809083
8.808828
8.809151
8.809380
8.807583
8.809389
8.809847
8.810680
8.808932
8.799813
8.808196
8.807009
8.807693
8.805678
8.807952
8.809008
8.784295
8.761069
8.799719
8.802202
8.807122
8.800968
8.808683
8.786084
8.806757
8.810199
8.810814
8.804443
8.809737
8.799792
8.785147
8.787195
8.807767
8.785472
8.760032
8.806790
8.803952
8.809061
8.808117
8.803352
8.805220
8.808701
8.805355
8.781892
8.809078
8.810006
8.807284
8.803833
8.805367
8.782830
8.807577
8.800209
8.806229
8.809370
8.805824
8.810819
8.753739
8.806519
8.807067
8.809151
8.800525
8.798834
8.810810
8.782031
8.806836
8.810804
8.809515
8.785551
8.810304
8.804762
8.807865
8.806938
8.810375
8.760226
8.784821
8.809446
8.808477
8.756651
8.808839
8.809212
8.781582