CSES - Datatähti 2021 loppu - Results
Submission details
Task:Suuremmat
Sender:T
Submission time:2021-01-23 17:36:08 +0200
Language:C++11
Status:READY
Result:35
Feedback
groupverdictscore
#1ACCEPTED35
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.01 s2details

Code

/**
 * Datatähti 2021 loppu
 * 358
 * A
 * Suuremmat
 * @author TRS
 */
//Include
#include <bits/stdc++.h>
//Definitions
using namespace std;
//Constants
#define infinity 0x3f3f3f3f
#define linfinity 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
int t;
unsigned long long n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    for (int _ = 0; _ < t; _++) {
        cin>>n;
        int maxPowerOf10 = floor(log10(n));
        if (n < 9) {
            cout<<(n + 1)<<"\n";
            continue;
        }
        else if (n < 11) {
            cout<<11<<"\n";
            continue;
        }
        else {
            short firstDigit = floor(n / pow(10, maxPowerOf10));
            short secondDigit = (int)floor(n / pow(10, maxPowerOf10 - 1)) % 10;
            if (firstDigit > secondDigit) {
                for (int d = 0; d <= maxPowerOf10; d++) {
                    cout<<firstDigit;
                }
            }
            else if (firstDigit < secondDigit) {
                for (int d = 0; d <= maxPowerOf10; d++) {
                    cout<<(firstDigit + 1);
                }
            }
            else { //firstDigit == secondDigit
                if (maxPowerOf10 == 1) {
                    if (firstDigit == 9) {
                        cout<<"111"<<"\n";
                        continue;
                    }
                    cout<<(firstDigit + 1)<<(firstDigit + 1)<<"\n";
                    continue;
                }
                int hasGreaterDigitAtEnd = 0;
                int allDigitsAreTheSame = 1;
                unsigned long long tempn = n;
                for (int d = 0; d <= maxPowerOf10; d++) {
                    int digit = tempn % 10;
                    tempn /= 10;
                    if (digit != firstDigit) {
                        allDigitsAreTheSame = 0;
                    }
                    if (digit > firstDigit) {
                        hasGreaterDigitAtEnd = 1;
                        break;
                    }
                }
                if (hasGreaterDigitAtEnd || allDigitsAreTheSame) {
                    if (firstDigit == 9) {
                        for (int d = 0; d <= maxPowerOf10 + 1; d++) {
                            cout<<"1";
                        }
                    }
                    else {
                        for (int d = 0; d <= maxPowerOf10; d++) {
                            cout<<(firstDigit + 1);
                        }
                    }
                }
                else {
                    for (int d = 0; d <= maxPowerOf10; d++) {
                        cout<<firstDigit;
                    }
                }
            }
            cout<<"\n";
        }
    }
    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:

input
1000
735425311146082632
756615631808964686
466489470801941584
100417544394053220
...

correct output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...

user output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...