QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355675#7942. $K$ Subsequencespipoika#WA 1ms3584kbC++172.1kb2024-03-17 01:49:052024-03-17 01:49:06

Judging History

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

  • [2024-03-17 01:49:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-03-17 01:49:05]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for (int i=j;i<(k);++i)
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vector<bool> a;
vi b;
int n,k;



bool check(int cap){
    set<tuple<int,int>> current;
    rep(i,0,k){
        current.insert({0,i});
    }
    rep(i,0,n){
        b[i] = -1;
    }
    vi full;
    rep(i,0,n){
        if(a[i]){
            if (full.size() == k){
                return false;
            }
            auto back = current.end();
            back--;

            auto [f, j] = *back;
            b[i] = j;
            current.erase(back);
            if (f + 1 == cap){
                full.push_back(j);
            }
            else{
                current.insert({f+1, j});
            }
        }
        else{
            if (full.size()){
                int j = full.back();
                full.pop_back();
                b[i] = j;
                current.insert({0, j});
            }
            else {
                auto back = current.end();
                back--;
                auto [f,j] = *back;
                b[i] = j;
                current.erase(back);
                current.insert({0, j});
            }
        }
    }
    return true;

}

int main() {
    int tc;
    cin >> tc;
    rep(_,0,tc){
        cin >> n >> k;
        a.resize(n);
        b.resize(n);
        bool positive = false;
        rep(i,0,n){
            int c;
            cin >> c;
            a[i] = c > 0;
            if (a[i]) positive = true;
        }
        if (!positive){
            rep(i,0,n){
                cout << 1 << " ";
            }
            cout << endl;
            continue;
        }

        int lo = 1;
        int hi = n/k+2;
        vi best;
        while (lo < hi){
            int med = (lo + hi) / 2;
            if (check(med)){
                best = b;
                                hi = med;
            }
            else {
                                lo = med + 1;

            }
        }
        rep(i,0,n){
            cout << best[i]+1 << " ";
        }
        cout << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

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:

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

result:

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