QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#579251 | #9310. Permutation Counting 4 | huanmeng | WA | 0ms | 3496kb | C++14 | 1.1kb | 2024-09-21 11:03:23 | 2024-09-21 11:03:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<pair<int, int>> ranges(n);
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
ranges[i] = {l, r};
}
// 排序区间,先按左端点排序,若左端点相同按右端点排序
sort(ranges.begin(), ranges.end());
bool possible = true;
int used = 1; // 从1开始分配数值
for (int i = 0; i < n; i++) {
if (ranges[i].first > used || ranges[i].second < used) {
possible = false; // 如果区间不能容纳当前数字,说明不可能有合法排列
break;
}
used++; // 为下一个位置分配数值
}
if (possible) {
cout << "1\n"; // 存在合法排列,奇数个
} else {
cout << "0\n"; // 不存在合法排列
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3496kb
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 1
result:
wrong answer 4th words differ - expected: '0', found: '1'