QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591970#2832. Graph Theorylonelywolf#WA 0ms3844kbC++201.2kb2024-09-26 19:34:242024-09-26 19:34:25

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 19:34:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-09-26 19:34:24]
  • 提交

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'