CSES - Datatähti Open 2021 - Results
Submission details
Task:Greater Integers
Sender:apostoldaniel854
Submission time:2021-01-29 20:44:38 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll INF = 2e18;
ll get (int cif, int nrcif) {
    ll ans = 0;
    for (int i = 0; i < nrcif; i++) {
        if (ans > INF / 10)
            ans = INF;
        else
            ans = ans * 10;
        ans += cif;
    }
    return ans;
}

void solveTest () {
    ll n;
    cin >> n;
    int nrcif = 0;
    ll n_copy = n;
    while (n_copy)
        nrcif++, n_copy /= 10;
    if (get (9, nrcif) <= n) cout << get (1, nrcif + 1) << "\n";
    else {
        int cif = 9;
        while (cif > 0 && get (cif - 1, nrcif) > n)
            cif--;
        if (cif > 0)
            cout << get (cif, nrcif) << "\n";
        else
            cout << get (9, nrcif - 1) << "\n";
    }
}

int main () {
    int t;
    cin >> t;
    while (t--)
        solveTest ();
    return 0;
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1000
1
2
3
4
...

correct output
2
3
4
5
6
...

user output
2
3
4
5
6
...

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
735425311146082632
756615631808964686
466489470801941584
100417544394053220
...

correct output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...

user output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...