CSES - Datatähti 2022 loppu - Results
Submission details
Task:Lista
Sender:MojoLake
Submission time:2022-01-22 16:11:29 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1--1, 2, 3details
#2--2, 3details
#3--3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#60.01 s1, 2, 3details
#7ACCEPTED0.01 s1, 2, 3details
#8--3details
#9--3details
#10--3details

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[9];
    int ans[n][9];
    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){

            int new_s[9];

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

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

                else{
                    new_s[i] = c-'0';
                }

            }
            for(int i = 0; i < m; ++i){
                prevstring[i] = new_s[i];
                ans[h][i] = new_s[i];
            }
            prevlen = newlen;
        }


        else{

            bool tight = 1;
            int new_s[9];

            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;
                    }

                }

                new_s[i] = x;
            }

            else if(c=='?'){

                if(!tight){
                    if(i==0){
                        new_s[i] = 1;
                    }
                    else{
                        new_s[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";
                        new_s[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; ++i){

                        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];
                        new_s[i] = newc;

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

                    }


                }


            }
        }
            for(int i = 0; i < m; ++i){
                prevstring[i] = new_s[i];
                ans[h][i] = new_s[i];
            }
            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
(empty)

Test 2

Group: 2, 3

Verdict:

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

correct output
800
1080
1081
1082
1083
...

user output
(empty)

Test 3

Group: 3

Verdict:

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

correct output
100000
1000090
1098000
1098050
4100001
...

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
?
?
?
?
...

correct output
1
2
3
4
5
...

user output
1
2
3
4
5
...
Truncated

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:

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

correct output
100000000
100000001
100000002
100000003
100000004
...

user output
(empty)

Test 9

Group: 3

Verdict:

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

correct output
100000000
101000000
102000000
103000000
104000000
...

user output
(empty)

Test 10

Group: 3

Verdict:

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

correct output
100100000
101000000
101100000
102000000
102100000
...

user output
(empty)