QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#284882#7942. $K$ Subsequencesucup-team093#WA 1ms3488kbC++201.7kb2023-12-16 15:26:562023-12-16 15:26:56

Judging History

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

  • [2023-12-16 15:26:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3488kb
  • [2023-12-16 15:26:56]
  • 提交

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];
    if(-1 == *max_element(a.begin(), a.end())) {
        for(int i = 0; i < n; i ++)
            cout << "1" << " \n"[i + 1 == n];
        return;
    }
    int l = 0, 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;
            
            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: 1ms
memory: 3488kb

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)