CSES - Datatähti 2022 loppu - Results
Submission details
Task:Lista
Sender:MojoLake
Submission time:2022-01-22 16:59:56 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s2, 3details
#30.01 s3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#60.01 s1, 2, 3details
#7ACCEPTED0.01 s1, 2, 3details
#8ACCEPTED0.01 s3details
#90.01 s3details
#10ACCEPTED0.01 s3details

Code

#include <bits/stdc++.h>

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;
    ll prevlen = 0;
    int prevstring[10];
    int ans[n][10];
    int arr[n];
    int orgn = n;
    vector<string> ss(n);;
    for(int i = 0; i < n; ++i){
        cin >> ss[i];
    }

    for(int h = 0; h < n; ++h){
        int newlen = 0;
        string s = ss[h];
        int m = s.size();
        arr[h] = m;
        if(m<prevlen){
            cout << "IMPOSSIBLE\n";
            return 0;
        }


        else if(m>prevlen){

            for(int i = 0; i < m; ++i){
                newlen++;
                char c = s[i];

                if(c=='?'){
                    if(!i){
                        prevstring[i] = ans[h][i] =  1;
                    }
                    else{
                        prevstring[i] = ans[h][i] =  0;
                    }
                }

                else{
                    prevstring[i] = ans[h][i] =  c-'0';
                }

            }
            prevlen = newlen;
        }


        else{

            bool tight = 1;

            for(int i = 0; i < m; ++i){
                newlen++;
                char c = s[i];

                if(c!='?'){

                    int prev_x = prevstring[i];
                    int x = c - '0';


                if(tight){

                    if(prev_x>x){
                        cout << "IMPOSSIBLE\n";
                        return 0;
                    }

                    else if(prev_x<x){
                        tight = 0;
                    }

                }

                prevstring[i] = ans[h][i] =  x;
            }

            else if(c=='?'){

                if(!tight){
                    if(i==0){
                        prevstring[i] = ans[h][i] =  1;
                    }
                    else{
                        prevstring[i] = ans[h][i] =  0;
                    }
                }

                else if(tight){

                    if(i==m-1){
                        if(prevstring[i]==9){
                            cout << "IMPOSSIBLE\n";
                            return 0;
                        }
                        int new_c = prevstring[i];
                        new_c++;
                        //cout << x << " " << add << "\n";
                        //cout << "newwccwew: " << new_c << " " << add << "\n";
                        prevstring[i] = ans[h][i] = new_c;
                        continue;

                    }
                    //we want to check the next element whether it is fine
                    bool putequal = 1;
                    for(int k = i+1; k < m; ++k){

                        if(s[k]=='?'&&prevstring[k]!=9)break;

                        else if(s[k]=='?'&&prevstring[k]==9 && k!= m-1)continue;

                        else if(s[k]=='?'&&prevstring[k]==9 && k == m-1){
                            putequal=0;
                            break;
                        }
                        int cur = s[k] - '0';
                        int pr = prevstring[k];
                        if(cur>pr)break;
                        else if(cur==pr)continue;
                        putequal = 0;
                        break;

                    }
                    if(putequal){

                        int newc = prevstring[i];
                        prevstring[i] = ans[h][i] =  newc;

                    }
                    else{
                        tight = 0;
                        if(prevstring[i]==9){
                            cout << "IMPOSSIBLE\n";
                            return 0;
                        }
                        int newc = prevstring[i];
                        newc++;
                        prevstring[i] = ans[h][i] = newc;

                    }


                }


            }
        }
            prevlen = newlen;

        }
    }
    for(int i = 0; i < orgn; ++i){
        for(int k = 0; k < arr[i]; ++k){
            cout << ans[i][k];
        }
        cout << "\n";
    }

    return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100
??
??
??
??
...

correct output
10
11
12
13
20
...

user output
10
11
12
13
20
...

Test 2

Group: 2, 3

Verdict:

input
1000
8??
??8?
????
????
...

correct output
800
1080
1081
1082
1083
...

user output
800
1080
1081
1082
1083
...

Test 3

Group: 3

Verdict:

input
1000
??????
?????9?
??98???
?????5?
...

correct output
100000
1000090
1098000
1098050
4100001
...

user output
100000
1000090
1098000
1098050
4100001
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
?
?
?
?
...

correct output
1
2
3
4
5
...

user output
1
2
3
4
5
...

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
2
???
??

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Group: 1, 2, 3

Verdict:

input
3
123
???
124

correct output
IMPOSSIBLE

user output
123
124
124

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
1??
???
2??
???
...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 8

Group: 3

Verdict: ACCEPTED

input
1000
?????????
?????????
?????????
?????????
...

correct output
100000000
100000001
100000002
100000003
100000004
...

user output
100000000
100000001
100000002
100000003
100000004
...

Test 9

Group: 3

Verdict:

input
900
???000000
???000000
???000000
???000000
...

correct output
100000000
101000000
102000000
103000000
104000000
...

user output
100000000
100000000
100000000
100000000
100000000
...

Test 10

Group: 3

Verdict: ACCEPTED

input
1000
???1?????
???0?????
???1?????
???0?????
...

correct output
100100000
101000000
101100000
102000000
102100000
...

user output
100100000
101000000
101100000
102000000
102100000
...