QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591970 | #2832. Graph Theory | lonelywolf# | WA | 0ms | 3844kb | C++20 | 1.2kb | 2024-09-26 19:34:24 | 2024-09-26 19:34:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
while (cin >> n >> m) {
vector<pair<int, int>> t(m);
for (auto &[x, y] : t) {
cin >> x >> y;
if (x > y) {
swap(x, y);
}
}
auto check = [&](int d) {
vector<int> cnt(m + 1);
auto add = [&](int l, int r) {
cnt[l]++;
if (r < n) {
cnt[r + 1]--;
}
};
for (auto [x, y] : t) {
if (x == y) {
add(1, n);
continue;
}
int d1 = y - x;
int d2 = m - d1;
if (d1 <= d && d2 <= d) {
add(1, n);
} else if (d1 > d && d2 <= d) {
add(x, y - 1);
} else if (d1 <= d && d2 > d) {
if (x > 1) {
add(1, x - 1);
}
add(y, n);
} else {
return false;
}
}
int s = 0;
for (int i = 1; i <= n; i++) {
s += cnt[i];
if (s == m) {
return true;
}
}
return false;
};
int l = -1, r = m;
while (l + 1 != r) {
int mid = (l + r) / 2;
if (check(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
input:
3 2 1 2 2 3 3 2 1 1 2 2 3 3 1 2 2 3 3 1
output:
1 0 2
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
2 1 1 2
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'