QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#284865#7942. $K$ Subsequencesucup-team093#WA 0ms3604kbC++201.6kb2023-12-16 15:22:472023-12-16 15:22:47

Judging History

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

  • [2023-12-16 15:22:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3604kb
  • [2023-12-16 15:22:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), tmp(n), ans;
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    int l = -1, r = n;
    while(l + 1 < r) {
        int mid = (l + r) / 2;
        if([&n, &k, &a, &tmp](int len) {
            vector<int> full, c(k + 1, len);
            queue<int> q;
            if(len) {
                for(int i = 1; i <= k; i ++)
                    q.push(i);
            }
            for(int i = 0; i < n; i ++) {
                if(a[i] == 1) {
                    if(q.empty()) return false;
                    tmp[i] = q.front();
                    if(--c[q.front()] == 0) {
                        full.push_back(q.front());
                        q.pop();
                    }
                }else{
                    if(full.size()) {
                        q.push(full.back());
                        tmp[i] = full.back();
                        c[full.back()] = len;
                        full.pop_back();
                    }else{
                        tmp[i] = q.front();
                        c[q.front()] = len;
                    }
                }
            }
            return true;
        }(mid)) {
            ans = tmp;
            r = mid;
        }
        else l = mid;
    }
    for(int i = 0; i < n; i ++)
        cout << ans[i] << " \n"[i + 1 == n];
}

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

    int T;
    cin >> T;
    while(T --)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3604kb

input:

5
3 2
1 -1 1
4 2
-1 1 1 -1
7 3
1 1 1 1 1 1 1
10 3
1 1 1 1 -1 -1 1 1 1 1
12 4
1 1 1 1 -1 -1 -1 -1 1 1 1 1

output:

1 1 2
1 1 2 2
1 1 1 2 2 2 3
1 1 2 2 2 1 3 3 2 2
1 2 3 4 4 3 2 1 4 3 2 1

result:

wrong answer Jury found better answer than participant (test case 4)