QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707747#7942. $K$ Subsequencesbilbo_b#WA 0ms3788kbC++173.0kb2024-11-03 17:21:252024-11-03 17:21:25

Judging History

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

  • [2024-11-03 17:21:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2024-11-03 17:21:25]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define x first
#define y second

using namespace std;

signed main() {
    // cin.tie(0);
    // cout.tie(0);
    // ios_base::sync_with_stdio(0);

    int t;
    cin >> t;
    while(t--) {
        int n, k, x;
        cin >> n >> k;
        vector<int> a(n);
        vector<int> ans(n);

        for (auto &i : a) {
            cin >> i;
        }
        
        int l = 0, r = n;
        vector<int> last_ans(n, 1);
        while(l < r) {
            ans.resize(n, 0);
            int mx = (l + r) / 2;

            bool f = true;
            set<pair<int, int> > s;
            vector<int> used;

            int last_used = 0;
            // cout << mx << endl;
            for (int i = 0; i < n; ++i) {
                // cout << i << endl;
                x = a[i];
                if(x == 1) {
                    if (mx == 0) {
                        f = false;
                        break;
                    }
                    if (used.size() == k) {
                        f = false;
                        break;
                    }

                    if (s.size()) {
                        auto t = *s.rbegin();
                        s.erase(t);
                        // cout << "t " << t.x << " " << t.y << endl;
                        ans[i] = t.y;
                        if (t.x + 1 == mx) {
                            used.push_back(t.y);
                        } else {
                            s.insert({t.x + 1, t.y});
                        }
                    } else {
                        // cout << "last_used " << last_used << endl;
                        last_used += 1;
                        ans[i] = last_used;
                        if (mx == 1) {
                            used.push_back(last_used);
                        } else {
                            s.insert({1, last_used});
                        }
                    }
                } else {
                    // cout << "here" << endl;
                    if (used.empty()) {
                        // cout << "here1 " << i << endl;
                        ans[i] = 1;
                        // cout << "here2" << endl;
                    } else {
                        int t = used.back();
                        used.pop_back();
                        ans[i] = t;
                        s.insert({0, t});
                    }
                    // cout << "here_end" << endl;
                }
                // cout << i << " " << ans[i] << endl;
            }
            // cout << endl;

            // cout << mx << " " << f << endl;

            if (f) {
                r = mx;
                last_ans = move(ans);
            } else {
                // cout << "here" << endl;
                l = mx + 1;
            }
        }
        for (auto i : last_ans) {
            cout << i << " ";
        }
        cout << '\n';
    }
 
    return 0;
}

詳細信息

Test #1:

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

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

result:

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