QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355678#7942. $K$ Subsequencespipoika#WA 57ms3808kbC++172.2kb2024-03-17 02:00:132024-03-17 02:00:15

Judging History

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

  • [2024-03-17 02:00:15]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:3808kb
  • [2024-03-17 02:00:13]
  • 提交

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({cap-1, j});
            }
            else {
                auto back = current.end();
                back--;
                auto [f,j] = *back;
                b[i] = j;
                current.erase(back);
                current.insert({f-1, 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: 100
Accepted
time: 1ms
memory: 3808kb

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 1 2 1 
3 3 3 2 2 2 1 
3 3 2 2 2 3 3 2 1 1 
4 3 2 1 1 2 3 4 4 3 2 1 

result:

ok Correct (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 57ms
memory: 3600kb

input:

18434
10 1
-1 1 1 -1 -1 1 -1 -1 1 1
10 2
-1 -1 -1 1 1 -1 1 1 1 1
10 2
1 -1 -1 -1 -1 1 1 -1 1 1
10 7
1 1 -1 1 -1 1 1 -1 -1 1
9 1
-1 1 -1 1 1 -1 1 -1 1
8 1
-1 -1 -1 -1 1 1 -1 -1
10 3
-1 -1 -1 1 1 1 1 -1 -1 -1
9 1
1 -1 -1 1 -1 -1 -1 -1 -1
10 10
-1 1 1 1 1 1 1 1 1 1
10 4
-1 1 -1 1 -1 1 1 -1 1 1
9 3
1 1 ...

output:

1 1 1 1 1 1 1 1 1 1 
2 1 2 1 1 1 1 2 2 2 
2 2 2 1 2 1 1 1 1 2 
7 6 6 6 6 6 5 5 6 6 
1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 
3 2 1 3 3 2 2 2 3 3 
1 1 1 1 1 1 1 1 1 
10 9 8 7 6 5 4 3 2 1 
4 3 3 3 3 3 2 2 2 1 
3 2 2 3 3 3 3 3 3 
4 3 3 3 2 1 1 1 
7 6 5 4 3 2 1 7 1 7 
6 6 6 5 5 5 4 3 3 
1 1 1 1 1 1 1 1 1 
3 ...

result:

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