CSES - Datatähti 2022 loppu - Results
Submission details
Task:Lista
Sender:Mahtimursu
Submission time:2022-01-22 14:04:02 +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
#4ACCEPTED0.01 s1, 2, 3details
#50.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>

typedef long long ll;

#define M 1000000007
#define N (1 << 18)

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    vector<string> ans;

    string cur = v[0];

    for (int i = 0; i < (int)cur.size(); ++i) {
        if (cur[i] == '?') {
            if (i == 0) {
                cur[i] = '1';
            } else {
                cur[i] = '0';
            }
        }
    }

    ans.push_back(cur);

    for (int i = 1; i < n; ++i) {
        if (cur.size() < v[i].size()) {
            // Just make low
            cur = v[i];
            for (int j = 0; j < (int)cur.size(); ++j) {
                if (cur[j] == '?') {
                    if (j == 0) {
                        cur[j] = '1';
                    } else {
                        cur[j] = '0';
                    }
                }
            }

            ans.push_back(cur);
        } else {
            // Improve
            bool gt = false;
            int len = cur.size();
            string orig = v[i];
            for (int j = 0; j < len; ++j) {
                if (v[i][j] != '?') {
                    if (v[i][j] > cur[j]) gt = 1;
                    if (v[i][j] < cur[j] && !gt) {
                        for (int k = j - 1; k >= -1; k--) {
                            if (k == -1) {
                                cout << "IMPOSSIBLE\n";
                                return 0;
                            }

                            if (orig[k] == '?') {
                                if (v[i][k] != '9') {
                                    v[i][k]++;
                                    break;
                                } else {
                                    v[i][k] = '0';
                                }
                            }
                        }
                        gt = 1;
                    }
                } else {
                    if (j != len - 1 || gt) {
                        if (gt) {
                            v[i][j] = '0';
                        } else {
                            v[i][j] = cur[j];
                        }
                    } else {
                        if (cur[j] != '9') {
                            v[i][j] = cur[j] + 1;
                        } else {
                            v[i][j] = '0';
                            for (int k = j - 1; k >= -1; k--) {
                                if (k == -1) {
                                    cout << "IMPOSSIBLE\n";
                                    return 0;
                                }

                                if (orig[k] == '?') {
                                    if (v[i][k] != '9') {
                                        v[i][k]++;
                                        break;
                                    } else {
                                        v[i][k] = '0';
                                    }
                                }
                            }
                        }
                    }
                }
            }

            cur = v[i];
            ans.push_back(cur);
        }
    }

    for (auto x : ans) {
        cout << x << "\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
...
Truncated

Test 2

Group: 2, 3

Verdict:

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

correct output
800
1080
1081
1082
1083
...

user output
800
1080
1081
1082
1083
...
Truncated

Test 3

Group: 3

Verdict:

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

correct output
100000
1000090
1098000
1098050
4100001
...

user output
100000
1000090
1098000
1098050
4100001
...
Truncated

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:

input
2
???
??

correct output
IMPOSSIBLE

user output
100
11

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

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

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