CSES - Datatähti 2021 loppu - Results
Submission details
Task:Suuremmat
Sender:T
Submission time:2021-01-23 18:29:54 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#2ACCEPTED0.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;
        }
        short firstDigit = floor(n / pow(10, maxPowerOf10));
        short secondDigit = (int)floor(n / pow(10, maxPowerOf10 - 1)) % 10;
        if (firstDigit == secondDigit && maxPowerOf10 == 1) {
            if (firstDigit == 9) {
                cout<<"111"<<"\n";
                continue;
            }
            cout<<(firstDigit + 1)<<(firstDigit + 1)<<"\n";
            continue;
        }
        if (firstDigit > secondDigit) {
            for (int d = 0; d <= maxPowerOf10; d++) {
                cout<<firstDigit;
            }
            cout<<"\n";
            continue;
        }
        else if (firstDigit < secondDigit) {
            for (int d = 0; d <= maxPowerOf10; d++) {
                cout<<(firstDigit + 1);
            }
            cout<<"\n";
            continue;
        }
        else { //firstDigit == secondDigit
            vector<int> digits;
            unsigned long long tempn = n;
            for (int d = 0; d <= maxPowerOf10; d++) {
                int digit = tempn % 10;
                digits.push_back(digit);
                tempn /= 10;
            }
            reverse(digits.begin(), digits.end());
            int printFirstDigit = 0;
            for (int i = 0; i <= maxPowerOf10; i++) {
                if (digits[i] < firstDigit) {
                    printFirstDigit = 1;
                    break;
                }
                else if (digits[i] > firstDigit) {
                    break;
                }
            }
            if (printFirstDigit) {
                for (int d = 0; d <= maxPowerOf10; d++) {
                    cout<<firstDigit;
                }
            }
            else {
                for (int d = 0; d <= maxPowerOf10; d++) {
                    cout<<(firstDigit + 1);
                }
            }
            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: ACCEPTED

input
1000
735425311146082632
756615631808964686
466489470801941584
100417544394053220
...

correct output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...

user output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
55555555555555
...
Truncated