QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569099 | #9310. Permutation Counting 4 | Echo | WA | 284ms | 3824kb | C++14 | 3.7kb | 2024-09-16 20:29:11 | 2024-09-16 20:29:11 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
// Define an interval as a pair of integers
typedef pair<int, int> Interval;
// Function to compute the symmetric difference of two interval lists
vector<Interval> symmetric_difference(const vector<Interval>& A, const vector<Interval>& B) {
vector<Interval> result;
int i = 0, j = 0;
int n = A.size(), m = B.size();
while (i < n || j < m) {
Interval next;
if (i < n && (j >= m || A[i] < B[j])) {
next = A[i++];
} else if (j < m && (i >= n || B[j] < A[i])) {
next = B[j++];
} else {
// Overlapping intervals
Interval a = A[i++], b = B[j++];
// Compute the symmetric difference of overlapping intervals
vector<Interval> temp;
if (a.first < b.first) temp.push_back({a.first, b.first - 1});
if (b.first < a.first) temp.push_back({b.first, a.first - 1});
if (a.second > b.second) temp.push_back({b.second + 1, a.second});
if (b.second > a.second) temp.push_back({a.second + 1, b.second});
for (auto& t : temp) {
if (!result.empty() && result.back().second + 1 >= t.first) {
result.back().second = max(result.back().second, t.second);
} else {
result.push_back(t);
}
}
continue;
}
// Add or merge intervals
if (!result.empty() && result.back().second + 1 >= next.first) {
result.back().second = max(result.back().second, next.second);
} else {
result.push_back(next);
}
}
return result;
}
// Function to check if column c is in any interval of row
bool column_in_row(const vector<Interval>& intervals, int c) {
for (auto& interval : intervals) {
if (c >= interval.first && c <= interval.second) return true;
if (interval.first > c) break;
}
return false;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
vector<vector<Interval>> rows(n);
bool possible = true;
for (int i = 0; i < n; ++i) {
int l, r;
scanf("%d%d", &l, &r);
if (l > r) {
possible = false;
}
rows[i].push_back({l, r});
}
if (!possible) {
printf("0\n");
continue;
}
vector<int> row_indices(n);
for (int i = 0; i < n; ++i) row_indices[i] = i;
bool determinant = true;
for (int c = 1; c <= n; ++c) {
int pivot_row = -1;
for (int r = c - 1; r < n; ++r) {
if (column_in_row(rows[row_indices[r]], c)) {
pivot_row = r;
break;
}
}
if (pivot_row == -1) {
determinant = false;
break;
}
if (pivot_row != c - 1) {
swap(row_indices[c - 1], row_indices[pivot_row]);
}
int pivot = row_indices[c - 1];
vector<Interval>& pivot_intervals = rows[pivot];
for (int i = 0; i < n; ++i) {
if (i == c - 1) continue;
int row_i = row_indices[i];
if (column_in_row(rows[row_i], c)) {
// Perform row operation: rows[row_i] ^= rows[pivot]
rows[row_i] = symmetric_difference(rows[row_i], pivot_intervals);
}
}
}
printf("%d\n", determinant ? 1 : 0);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2
output:
0 1 0 0
result:
ok 4 tokens
Test #2:
score: -100
Wrong Answer
time: 284ms
memory: 3812kb
input:
66725 14 7 7 4 6 7 8 8 13 2 13 6 13 6 10 14 14 1 10 9 11 7 9 3 8 4 12 5 12 12 2 6 3 6 7 11 2 5 1 1 6 12 8 12 2 3 7 9 7 8 1 10 1 4 10 4 8 4 4 6 10 9 10 2 3 2 7 1 3 3 4 2 2 3 10 20 3 12 10 14 19 20 19 20 1 9 7 9 13 16 17 17 16 18 2 11 5 19 6 17 11 17 3 6 3 11 7 20 8 17 3 18 10 15 9 20 16 5 10 2 10 2 1...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st words differ - expected: '1', found: '0'