CSES - Datatähti 2022 loppu - Results
Submission details
Task:Lista
Sender:motsgar
Submission time:2022-01-22 16:38:47 +0200
Language:C++ (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
#40.01 s1, 2, 3details
#50.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#7ACCEPTED0.01 s1, 2, 3details
#8ACCEPTED0.01 s3details
#9ACCEPTED0.01 s3details
#100.01 s3details

Compiler report

input/code.cpp: In function 'int rec(int, int)':
input/code.cpp:11:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a==s[i].size())return -1;
        ~^~~~~~~~~~~~~
input/code.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(;a<s[0].size();a++){
                  ~^~~~~~~~~~~~
input/code.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(;a<s[0].size();a++){
                      ~^~~~~~~~~~~~
input/code.cpp:84:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(;a<s[0].size();a++){
                      ~^~~~~~~~~~~~
input/code.cpp:97:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(;a<s[0].size();a++){
                  ~^~~~~~~~~~~~
input/code.cpp:105:23: warning: comparison between signed and un...

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int n;
string s[1000];
string e[1000];

int rec(int i,int a){
    if(a==s[i].size())return -1;
    if(e[i][a]=='.'){
        return rec(i,a+1);
    }
    if(a==0||e[i][a-1]=='.'){
        if(i==0){
            if(s[i][a]=='?'){
                s[i][a]='1';
                rec(i,a+1);
                return 0;
            } else {
                rec(i,a+1);
                return 0;
            }
        }
        if(s[i][a]=='?'){
            s[i][a]=s[i-1][a];
            if(s[i][a]=='0')s[i][a]='1';
            int r=rec(i,a+1);
            if(r==-1){
                if(s[i][a]=='9')return -1;
                s[i][a]++;
                return 0;
            }
            return 0;
        } else if(s[i][a]==s[i-1][a]){
            if(s[i][a]=='0')return -1;
            int r=rec(i,a+1);
            if(r==-1){
                return -1;
            }
            return 0;
        } else if(s[i][a]>s[i-1][a]){
            a++;
            for(;a<s[0].size();a++){
                s[i][a]='0';
            }
            return 0;
        } else return -1;
    } else {
        if(i==0){
            if(s[i][a]=='?'){
                s[i][a]='0';
                rec(i,a+1);
                return 0;
            } else {
                rec(i,a+1);
                return 0;
            }
        }
        if(s[i][a]=='?'){
            if(e[i-1][a-1]=='.'){
                a++;
                for(;a<s[0].size();a++){
                    if(s[i][a]=='?')
                    s[i][a]='0';
                }
                return 0;
            }
            s[i][a]=s[i-1][a];
            int r=rec(i,a+1);
            if(r==-1){
                if(s[i][a]=='9'){
                    s[i][a]='0';
                    return -1;
                }
                s[i][a]++;
                return 0;
            }
            return 0;
        } else if(s[i][a]==s[i-1][a]){
            if(e[i-1][a-1]=='.'){
                a++;
                for(;a<s[0].size();a++){
                    if(s[i][a]=='?')
                    s[i][a]='0';
                }
                return 0;
            }
            int r=rec(i,a+1);
            if(r==-1){
                return -1;
            }
            return 0;
        } else if(s[i][a]>s[i-1][a]){
            a++;
            for(;a<s[0].size();a++){
                if(s[i][a]=='?')
                s[i][a]='0';
            }
            return 0;
        } else {
            if(e[i-1][a-1]=='.'){
                a++;
                for(;a<s[0].size();a++){
                    if(s[i][a]=='?')
                    s[i][a]='0';
                }
                return 0;
            }
            return -1;
        }
    }
}

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

    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<n;i++){
        e[i]=string(s[n-1].size()-s[i].size(),'.')+s[i];
        s[i]=string(s[n-1].size()-s[i].size(),'0')+s[i];
        if(rec(i,0)==-1){
            cout<<"IMPOSSIBLE\n";
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        s[i].erase(0, e[i].find_first_not_of('.'));
        cout<<s[i]<<"\n";
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

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

correct output
10
11
12
13
20
...

user output
IMPOSSIBLE

Test 2

Group: 2, 3

Verdict:

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

correct output
800
1080
1081
1082
1083
...

user output
IMPOSSIBLE

Test 3

Group: 3

Verdict:

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

correct output
100000
1000090
1098000
1098050
4100001
...

user output
IMPOSSIBLE

Test 4

Group: 1, 2, 3

Verdict:

input
100
?
?
?
?
...

correct output
1
2
3
4
5
...

user output
1
2
3
4
5
...
Truncated

Test 5

Group: 1, 2, 3

Verdict:

input
2
???
??

correct output
IMPOSSIBLE

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
123
???
124

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

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
...
Truncated

Test 9

Group: 3

Verdict: ACCEPTED

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

correct output
100000000
101000000
102000000
103000000
104000000
...

user output
100000000
101000000
102000000
103000000
104000000
...
Truncated

Test 10

Group: 3

Verdict:

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

correct output
100100000
101000000
101100000
102000000
102100000
...

user output
100100000
1010?????
101100000
1020?????
102100000
...
Truncated