QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122516#87. Devil's Sharebashkort#14 45ms4004kbC++205.5kb2023-07-10 17:36:382024-07-04 00:36:06

Judging History

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

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

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int Lim = 10;

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] < Lim) {
            ++freq[x - 1];
            re += char('0' + x);
            rec();
            --freq[x - 1];
            re.pop_back();
        }
    }
}

constexpr int A = 10;

vector<int> put(int n, int rem, bool g = true) {
    vector<int> res(n);
    if (rem == 0) {
        return res;
    } else {
        if (g) {
            res[n - 1] = 1;
            rem -= 1;
            n -= 1;
        }
        if (rem * 2 < n) {
            vector<int> f = put(n, n - rem, false);
            reverse(f.begin(), f.end());
            for (int &x : f) {
                x = 1 - x;
            }
            copy(f.begin(), f.end(), res.begin());
            return res;
        } else {
            int s = rem / (n - rem);
            int rr = n - rem;
            for (int i = 0, p = n - 1; i < rem; ++i) {
                assert(p >= 0);
                res[p--] = 1;
                if (i % s == 0 && rr > 0) {
                    assert(p >= 0);
                    --rr;
                    res[p--] = 0;
                }
            }
            return res;
        }
    }
}

string even(array<int, 3> d) {
    if (d[1] == 0 || d[2] == 0) {
        return string(d[1], '1') + string( d[2], '2');
    }
    if (d[1] > d[2]) {
        string res;
        int cnt = d[1] / d[2];
        int rem = d[1] - d[2] * cnt;
        vector<int> p = put(d[2], rem);
        for (int i = 0; i < d[2]; ++i) {
            res += '2';
            res += string(cnt + p[i], '1');
        }
        return res;
    } else {
        string res;
        int cnt = d[2] / d[1];
        int rem = d[2] - d[1] * cnt;
        vector<int> p = put(d[1], rem);
        reverse(p.begin(), p.end());
        for (int i = 0; i < d[1]; ++i) {
            res += string(cnt + p[i], '2');
            res += '1';
        }
        return res;
    }
}

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 {
        string s = even({d[0], d[1], d[2]}) + string(k - 1, '2');
        return s;
    }

    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 <= Lim; ++one) {
            for (int two = 0; two <= Lim; ++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 << k << endl << one << " " << two << endl;
                        cout << "wrong: " << wrong << endl << "correct: " << correct << endl;
                        return 0;
                    }
                }
            }
        }
    }

    int test = 1;
    cin >> test;

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

    return 0;
}

詳細信息

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: 45ms
memory: 3620kb

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: 0
Accepted
time: 35ms
memory: 3628kb

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: 0
Accepted
time: 30ms
memory: 3600kb

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: 0
Accepted
time: 42ms
memory: 3548kb

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: 0
Accepted
time: 24ms
memory: 3540kb

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: 0
Accepted
time: 23ms
memory: 3616kb

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: 0
Accepted
time: 19ms
memory: 3512kb

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: 0
Accepted
time: 23ms
memory: 3536kb

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: 0
Accepted
time: 23ms
memory: 4004kb

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
Runtime Error

Test #11:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%