QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777608 | #9788. Shreckless | ucup-team3734# | WA | 36ms | 4136kb | C++23 | 2.0kb | 2024-11-24 04:24:07 | 2024-11-24 04:24:08 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
string canShrekSortRows(int n, int m, vector<vector<int>>& matrix) {
vector<vector<int>> sortedCols(m, vector<int>(n));
for (int j = 0; j < m; ++j) {
for (int i = 0; i < n; ++i) {
sortedCols[j][i] = matrix[i][j];
}
sort(sortedCols[j].begin(), sortedCols[j].end(), greater<int>());
}
priority_queue<int, vector<int>, greater<int>> minHeap; // Min-heap
int totalCount = 0;
// Step 2: Process columns
for (int j = m - 1; j >= 0; --j) {
int X = minHeap.empty() ? -1 : minHeap.top();
int localCount = 0;
if (minHeap.empty()) {
// If the heap is empty, add all column elements to the heap
for (int num : sortedCols[j]) {
minHeap.push(num);
}
continue;
}
// Step 3: Find the last number greater than X with totalCount + localCount <= heap size
for (int k = 0; k < n; ++k) {
if (sortedCols[j][k] > X && localCount <= minHeap.size()) {
localCount++;
} else {
for (int l = k; l < n; ++l) {
minHeap.push(sortedCols[j][l]);
}
break;
}
}
totalCount += localCount; // Accumulate the count
if (totalCount >= n) {
return "YES";
}
}
return "NO";
}
int main() {
int t;
cin >> t;
vector<string> results;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<int>> matrix(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> matrix[i][j];
}
}
results.push_back(canShrekSortRows(n, m, matrix));
}
// Output results for all test cases
for (const string& result : results) {
cout << result << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3480kb
input:
3 2 2 69 69 2024 42 3 3 1 1 1 1 1 1 2 2 2 3 4 1 1 1 1 1 1 1 1 2 2 2 2
output:
YES NO YES
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 2 2 69 69 2024 42 3 3 1 1 1 1 1 1 2 2 2 3 4 1 1 1 1 1 1 1 1 2 2 2 2
output:
YES NO YES
result:
ok 3 token(s): yes count is 2, no count is 1
Test #3:
score: -100
Wrong Answer
time: 36ms
memory: 4136kb
input:
20000 6 2 12 4 8 24 2 10 1 22 3 15 18 20 3 3 3 8 18 2 17 15 13 4 6 3 3 7 17 15 8 6 3 18 13 9 3 3 2 3 14 1 7 17 4 6 13 3 3 6 10 14 3 9 13 1 7 15 2 4 1 3 16 14 6 10 4 2 3 3 3 2 17 7 11 13 16 5 18 2 3 2 3 6 4 1 5 2 4 4 6 13 14 2 11 12 16 3 3 2 8 12 4 9 17 5 7 18 3 2 5 10 8 9 1 6 2 2 2 4 1 3 2 3 12 6 1 ...
output:
NO YES YES NO NO YES YES YES NO NO NO NO YES YES YES YES NO NO YES NO NO NO YES NO YES YES YES YES YES NO NO YES NO YES NO NO YES NO YES YES NO NO YES NO YES NO NO YES YES YES NO NO YES YES YES YES NO NO YES YES NO NO YES NO NO NO YES YES YES YES NO NO YES YES NO NO NO NO YES YES YES NO NO YES YES N...
result:
wrong answer expected NO, found YES [53rd token]