QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591973#2832. Graph Theorylonelywolf#WA 0ms3560kbC++201.2kb2024-09-26 19:36:492024-09-26 19:36:49

Judging History

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

  • [2024-09-26 19:36:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-09-26 19:36:49]
  • 提交

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;
}  

Details

Tip: Click on the bar to expand more detailed information

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'