QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#837052#9574. StripslaonongminWA 0ms3516kbC++201.7kb2024-12-29 14:28:572024-12-29 14:28:57

Judging History

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

  • [2024-12-29 14:28:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3516kb
  • [2024-12-29 14:28:57]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// 检查条带是否合法(不覆盖黑色单元格)
bool is_valid(const vector<int>& red_cells, const vector<int>& black_cells, int left, int k) {
    for (int b : black_cells) {
        for (int i = left; i < left + k; i++) {
            if (i == b) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, m, k, w;
        cin >> n >> m >> k >> w;
        vector<int> red_cells(n);
        for (int i = 0; i < n; i++) {
            cin >> red_cells[i];
        }
        vector<int> black_cells(m);
        for (int i = 0; i < m; i++) {
            cin >> black_cells[i];
        }
        // 对红色单元格排序
        sort(red_cells.begin(), red_cells.end());
        int count = 0;
        int i = 0;
        vector<int> ans;
        while (i < n) {
            int left = red_cells[i];
            // 寻找合适的条带位置
            while (!is_valid(red_cells, black_cells, left, k)) {
                left++;
                if (left + k - 1>w) {
                    // 无法找到合适的条带位置
                    cout << -1 << endl;
                    goto end;
                }
            }
            count++;
            ans.push_back(left);
            i += k;
        }
        cout << count << endl;
        for (int j = 0; j < count; j++) {
            cout << ans[j];
            if (j!= count - 1) {
                cout << " ";
            }
        }
        cout << endl;
    end:;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
5 2 3 16
7 11 2 9 14
13 5
3 2 4 11
6 10 2
1 11
2 1 2 6
1 5
3
2 1 2 6
1 5
2

output:

2
2 14
1
2
1
1
1
3

result:

wrong answer There is no stripe covering red cell 7 (test case 1)