CSES - Datatähti 2021 loppu - Results
Submission details
Task:Suuremmat
Sender:T
Submission time:2021-01-23 16:38:40 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.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;
        if (n < 9) {
            cout<<(n + 1)<<"\n";
        }
        else if (n < 11) {
            cout<<11<<"\n";
        }
        else {
            int maxPowerOf10 = floor(log10(n));
            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) {
                    cout<<(firstDigit + 1)<<(firstDigit + 1)<<"\n";
                    continue;
                }
                int hasGreaterDigitAtEnd = 0;
                int allDigitsAreTheSame = 1;
                for (int d = 0; d <= maxPowerOf10 + 1; d++) {
                    int digit = n % 10;
                    n /= 10;
                    if (digit != firstDigit) {
                        allDigitsAreTheSame = 0;
                    }
                    if (digit > firstDigit) {
                        hasGreaterDigitAtEnd = 1;
                        break;
                    }
                }
                if (hasGreaterDigitAtEnd || allDigitsAreTheSame) {
                    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:

input
1000
1
2
3
4
...

correct output
2
3
4
5
6
...

user output
2
3
4
5
6
...
Truncated

Test 2

Group: 2

Verdict:

input
1000
735425311146082632
756615631808964686
466489470801941584
100417544394053220
...

correct output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...

user output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
55555555555555
...
Truncated