QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591973 | #2832. Graph Theory | lonelywolf# | WA | 0ms | 3560kb | C++20 | 1.2kb | 2024-09-26 19:36:49 | 2024-09-26 19:36:49 |
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(n + 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 = n - 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 = n;
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: 3560kb
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: 3508kb
input:
2 1 1 2
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'