QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122484#87. Devil's Sharebashkort#14 44ms3984kbC++204.9kb2023-07-10 16:24:352024-07-04 00:36:06

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:36:06]
  • 评测
  • 测评结果:14
  • 用时:44ms
  • 内存:3984kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 16:24:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;


map<array<int, 3>, string> dp, mp;

string re;
array<int, 3> freq;

string calc(int k, string s = re) {
    string res;
    for (int i = 0; i + k <= size(s); ++i) {
        res = max(res, s.substr(i, k));
    }
    return res;
}

void rec() {
    if (!re.empty()) {
        for (int k = 1; k <= size(re); ++k) {
            freq[2] = k;
            string res = calc(k);
            if (dp[freq].empty() || dp[freq] > res) {
                dp[freq] = res;
                mp[freq] = re;
            }
        }
    }
    for (int x = 1; x <= 2; ++x) {
        if (freq[x - 1] < 10) {
            ++freq[x - 1];
            re += char('0' + x);
            rec();
            --freq[x - 1];
            re.pop_back();
        }
    }
}

constexpr int A = 10;

string smart(int one, int two, int k) {
    int n = one + two;
    int d[3]{0, one, two};
    int x = d[2] ? 2 : 1;
    vector<int> ans(n);

    for (int i = 1; i < k; ++i) {
        ans[n - i] = x;
        if (--d[x] == 0) {
            x -= 1;
        }
    }

    if (d[2] == 0) {
        for (int i = k; i <= n; ++i) {
            ans[n - i] = 1;
        }
    } else {
        int cnt = d[2];
        int f = d[1] / cnt, p = 0;
        int rem = d[1] % cnt;
        if (rem == 0) {
            for (int i = 0; i < cnt; ++i) {
                ans[p++] = 2;
                int s = f;
                for (int t = 0; t < s; ++t) {
                    ans[p++] = 1;
                }
            }
        } else {
            if (rem * 2 >= cnt) {
                int step = cnt / (cnt - rem);
                int done = 0;
                for (int i = 0; i < cnt; ++i) {
                    ans[p++] = 2;
                    int s = i == cnt - 1 ? d[1] - done : f + (i % step != 0);
                    for (int t = 0; t < s; ++t) {
                        ++done;
                        ans[p++] = 1;
                    }
                }
            } else {
                int step = (cnt - 1) / rem + 1;
                int done = 0;
                p = n - k;
                for (int i = cnt - 1; i >= 0; --i) {
                    int s = i == 0 ? d[1] - done : f + ((cnt - 1 - i) % step == 0);
                    for (int t = 0; t < s; ++t) {
                        ++done;
                        ans[p--] = 1;
                    }
                    ans[p--] = 2;
                }
            }
        }
    }

    string str;
    for (int i = 0; i < n; ++i) {
        str += char('0' + ans[i]);
    }

    return str;
}

string stupid(int one, int two, int k) {
    return mp[{one, two, k}];
}

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

    int d[A]{}, dd[A]{};
    for (int i = 1; i < A; ++i) {
        cin >> d[i];
        dd[i] = d[i];
    }

    const int n = accumulate(d, d + A, 0);
    if (n == 1) {
        for (int i = A - 1; i >= 0; --i) {
            if (d[i]) {
                cout << i << '\n';
                return;
            }
        }
    }
    vector<int> ans(n);

    if (k == 2) {
        ans[n - 1] = A - 1;
        while (!d[ans.back()]) {
            --ans.back();
        }
        --d[ans.back()];
        int x = ans.back();
        while (!d[x]) {
            --x;
        }

        int p = n - 2;
        for (int i = 1; i < x; ++i) {
            while (d[i]--) {
                ans[p--] = i;
                if (d[x] > 0) {
                    ans[p--] = x;
                    --d[x];
                }
            }
        }
        while (d[x]--) {
            ans[p--] = x;
        }
    } else {
        cout << smart(d[1], d[2], k) << '\n';
        return;
    }

    for (int i = 0; i < n; ++i) {
        cout << ans[i];
        --dd[ans[i]];
    }
    for (int x : dd) {
        assert(x == 0);
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (0) {
        rec();

        for (int one = 0; one <= 10; ++one) {
            for (int two = 0; two <= 10; ++two) {
                if (!one && !two) {
                    continue;
                }
                for (int k = 1; k <= one + two; ++k) {
                    string wrong = smart(one, two, k);
                    string correct = stupid(one, two, k);
                    string resWrong = calc(k, wrong);
                    string resCorrect = calc(k, correct);
                    if (resWrong != resCorrect) {
                        cout << "found!\n";
                        cout << one << " " << two << " " << k << endl;
                        cout << "wrong: " << wrong << endl << "correct: " << correct << endl;
                        return 0;
                    }
                }
            }
        }
    }

    int test = 1;
    cin >> test;

    while (test--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1536
4
2 1 2 2 0 0 0 0 0
2
3 2 3 3 0 0 0 0 0
3
1 2 0 3 0 0 0 0 0
4
2 2 3 2 0 0 0 0 0
1
3 3 2 2 0 0 0 0 0
3
1 2 2 0 0 0 0 0 0
3
2 1 2 3 0 0 0 0 0
6
1 3 3 0 0 0 0 0 0
4
1 0 1 2 0 0 0 0 0
4
2 1 2 3 0 0 0 0 0
4
2 3 0 2 0 0 0 0 0
5
3 2 3 3 0 0 0 0 0
3
2 2 1 1 0 0 0 0 0
3
2 3 2 0 0 0 0 0 0
8
1 3 1 3 0 0 0...

output:


result:


Subtask #2:

score: 14
Accepted

Test #2:

score: 14
Accepted
time: 29ms
memory: 3604kb

input:

35960
2
0 0 5 2 0 0 17 0 7
2
0 6 0 15 0 0 0 4 5
2
3 0 0 1 20 0 0 0 8
2
0 5 0 0 15 0 5 7 0
2
0 0 2 11 0 0 4 0 10
2
0 14 0 0 11 0 0 6 1
2
0 0 10 3 0 0 8 0 1
2
0 1 9 0 2 0 0 6 0
2
0 0 0 0 5 0 12 7 3
2
0 0 5 0 0 2 0 8 9
2
7 2 0 0 0 0 0 6 8
2
0 0 0 4 1 0 3 18 0
2
0 0 14 4 8 0 0 0 1
2
0 2 0 0 0 13 3 9 0
2...

output:

7777777777777777749493939393939
888844444444444444422929292929
55555555555555555959595949191919
77777555555555555558582828282828
777744449494949494949493939
55555555555222222228282828282829
4443373737373737373739
553333383838383828
888888877777777777755595959
888888898969693939393939
888888229191919...

result:

ok Correct!

Test #3:

score: 14
Accepted
time: 35ms
memory: 3544kb

input:

23426
2
34 0 0 0 0 3 0 0 8
2
20 1 0 0 0 21 0 0 0
2
18 0 0 0 5 0 0 0 18
2
8 18 0 0 0 27 0 0 0
2
0 0 2 47 0 0 0 0 4
2
0 0 0 36 9 0 5 0 0
2
7 0 0 15 0 0 29 0 0
2
2 0 27 0 0 0 20 0 0
2
0 0 0 3 29 0 0 11 0
2
0 0 0 11 0 0 25 14 0
2
0 7 0 16 0 22 0 0 0
2
0 0 0 1 0 22 20 0 0
2
0 0 0 37 0 3 0 7 0
2
20 0 0 0 ...

output:

666111111111111111111111111111919191919191919
261616161616161616161616161616161616161616
55555191919191919191919191919191919191919
62626262626262626262626262626262626261616161616161616
44444444444444444444444444444444444444444444449493939
55555555544444444444444444444444444444444747474747
7777777474...

result:

ok Correct!

Test #4:

score: 14
Accepted
time: 34ms
memory: 3564kb

input:

19600
2
0 7 0 9 0 0 3 32 0
2
0 0 0 0 23 22 4 2 0
2
0 0 6 0 0 2 33 0 10
2
0 12 0 7 0 11 21 0 0
2
41 0 0 5 3 0 2 0 0
2
19 0 0 13 6 0 0 0 13
2
12 6 0 0 9 0 0 24 0
2
0 7 2 6 0 0 0 0 36
2
3 0 18 0 0 28 0 2 0
2
0 0 2 0 0 37 3 0 9
2
8 0 0 10 29 0 0 4 0
2
18 10 0 0 2 0 0 21 0
2
0 0 29 8 0 0 9 5 0
2
28 0 0 0...

output:

888888888888878787848484848484848484828282828282828
777766666666666666666666665555555555555555555555858
777777777777777777777777777777779796969393939393939
666666666676747474747474747272727272727272727272727
555444441111111111111111111111111111111111111111717
5555554444444444444111111191919191919191...

result:

ok Correct!

Test #5:

score: 14
Accepted
time: 44ms
memory: 3480kb

input:

40215
2
5 0 0 2 3 4 5 0 2
2
0 1 4 0 2 4 0 3 7
2
2 0 0 0 0 18 12 0 0
2
0 13 11 0 16 0 0 0 0
2
7 0 6 2 1 0 0 0 5
2
4 0 0 0 0 0 8 2 3
2
5 2 0 0 2 0 2 7 3
2
3 0 0 2 3 4 4 5 0
2
0 0 3 1 0 0 0 12 2
2
2 13 3 0 1 0 0 1 1
2
0 0 10 0 4 0 0 0 18
2
0 1 7 0 0 6 0 0 1
2
3 0 6 3 3 6 0 0 0
2
0 5 0 4 4 1 7 0 0
2
0 0...

output:

777776666555441111919
888666659593939393929
66666666676767676767676767671717
3333333335353525252525252525252525252525
544333333111919191919
88777777771191919
888888877552211191919
777766665554848181818
888888888888433939
533322222222222221819
99995959595939393939393939393939
336363636363629
55544433...

result:

ok Correct!

Test #6:

score: 14
Accepted
time: 24ms
memory: 3584kb

input:

1000
2
346 0 0 0 0 0 325 0 305
2
341 0 0 0 304 0 0 0 325
2
0 315 0 0 0 0 0 335 346
2
299 0 0 0 0 296 325 0 0
2
0 0 324 286 0 298 0 0 0
2
0 0 0 0 0 0 345 323 313
2
0 0 0 0 0 305 0 320 294
2
0 0 0 308 339 0 0 301 0
2
323 0 0 317 0 0 0 0 278
2
0 292 342 0 0 324 0 0 0
2
0 0 0 285 0 342 0 324 0
2
310 0 2...

output:

777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

result:

ok Correct!

Test #7:

score: 14
Accepted
time: 25ms
memory: 3604kb

input:

1000
2
232 0 0 223 0 211 0 0 244
2
0 0 0 0 233 277 222 0 252
2
0 250 230 0 0 0 241 0 242
2
248 241 248 0 0 219 0 0 0
2
223 0 0 0 253 240 226 0 0
2
0 0 0 251 0 235 0 239 263
2
267 245 0 220 260 0 0 0 0
2
261 0 0 0 0 256 250 221 0
2
0 240 229 0 0 236 243 0 0
2
0 236 0 248 0 252 242 0 0
2
0 0 239 250 0...

output:

666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666644444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

result:

ok Correct!

Test #8:

score: 14
Accepted
time: 20ms
memory: 3572kb

input:

1000
2
84 122 93 126 108 97 117 115 115
2
110 100 118 106 104 112 100 118 128
2
107 102 103 109 119 97 93 118 101
2
128 107 106 97 88 90 97 91 97
2
134 122 108 95 103 105 102 95 112
2
88 110 128 99 94 93 105 113 114
2
111 108 118 97 90 99 93 89 115
2
91 98 106 110 111 102 106 96 95
2
110 98 124 110 ...

output:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888877777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777766666666666666666666666666666666666666666666666666666666666666666666...

result:

ok Correct!

Test #9:

score: 14
Accepted
time: 23ms
memory: 3628kb

input:

100
2
1076 1058 1108 1113 1118 1160 1056 1150 1094
2
1097 1101 1124 1098 1085 1113 1122 1090 1081
2
1062 1049 1138 1063 1088 1029 1109 1149 1109
2
1005 1079 990 1015 1053 1013 1043 1059 995
2
1041 1043 1079 1092 1040 1079 1104 1057 1016
2
1012 1075 984 1082 1082 993 969 1019 987
2
939 1033 988 1061 ...

output:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

result:

ok Correct!

Test #10:

score: 14
Accepted
time: 19ms
memory: 3984kb

input:

10
2
10734 10761 10776 10789 10842 10844 10973 10952 10904
2
10639 10677 10586 10820 10717 10667 10636 10594 10659
2
10253 10248 10111 10247 10186 10246 10194 10096 10099
2
10301 10375 10306 10267 9994 10102 10124 10006 10162
2
10894 10878 10645 10624 10493 10697 10843 10738 10719
2
9953 10322 9896 ...

output:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

result:

ok Correct!

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 16ms
memory: 3492kb

input:

26488
21
7 19 0 0 0 0 0 0 0
3
15 21 0 0 0 0 0 0 0
7
4 35 0 0 0 0 0 0 0
5
28 12 0 0 0 0 0 0 0
22
40 3 0 0 0 0 0 0 0
1
7 6 0 0 0 0 0 0 0
5
12 21 0 0 0 0 0 0 0
18
27 13 0 0 0 0 0 0 0
2
36 6 0 0 0 0 0 0 0
15
19 14 0 0 0 0 0 0 0
34
17 20 0 0 0 0 0 0 0
11
17 5 0 0 0 0 0 0 0
19
10 12 0 0 0 0 0 0 0
28
29 9 ...

output:

11111112222222222222222222
221212122121212212121221212122121122
222221222222221222222221222222221222222
2111211112111211112111211112111211112222
1111111111111111111111111111111111111111222
2121212121211
221212212122121221212212122112222
1111111111111111111111111112222222222222
1111111111111111111111...

result:

wrong output format Extra information in the output file

Subtask #4:

score: 0
Skipped

Dependency #1:

0%