CSES - Datatähti Open 2021 - Results
Submission details
Task:Greater Integers
Sender:kenechi
Submission time:2021-01-31 11:30:48 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:22:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < s.size(); i++){
                        ~~^~~~~~~~~~
input/code.cpp:17:9: warning: unused variable 'pre' [-Wunused-variable]
     int pre = -1;
         ^~~

Code

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;

    n++;
    string s = to_string(n), ans = s;

    int pre = -1;
    for (int dgt = 1; dgt <= 9; dgt++) {
        int now = s.front() - '0';
        if (dgt < now)continue;
        bool make = true;
        for(int i = 0; i < s.size(); i++){
            if(s[i] - '0' < dgt)break;
            else if(s[i] - '0' > dgt){
                make = false;
                break;
            }
        }
        if (make) {
            ans = string(s.size(), dgt + '0');
            cout << ans << endl;
            return;
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

    while (t--)
        solve();
    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
...
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