QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#244706#2832. Graph TheoryDelay_for_five_minutes#TL 5ms12884kbC++11876b2023-11-09 14:41:332023-11-09 14:41:35

Judging History

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

  • [2023-11-09 14:41:35]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:12884kb
  • [2023-11-09 14:41:33]
  • 提交

answer

#include<bits/stdc++.h>
int n,m;
#define maxn 200005
void solve() {
	std::vector<int> pop[maxn],push[maxn];
	for(int i = 1 ; i <= m; i++) {
		int x,y;
		std::cin >> x >> y;
		if (y < x) std::swap(x,y);
		if (x == y) continue;
		push[1].push_back(y-x);
		pop[x].push_back(y-x);
		push[x].push_back(n-(y-x));
		pop[y].push_back(n-(y-x));
		push[y].push_back(y-x);
	}
	std::multiset<int> st;
	int ans = 1e9;
	for(int i = 1; i <= n; i++) {
		for(auto j : push[i]) {
			st.insert(j);
		}
		for(auto j : pop[i]) {
			st.erase(st.find(j));
		}
		if (st.empty()) {
			std::cout << 0 << std::endl;
			return ;
		}
		// for(auto v : st) {
		// 	printf("%d ",v);
		// }putchar('\n');
		ans = std::min(ans, *st.rbegin());
	}
	std::cout << ans << std::endl;
}
int main() {
	std::ios::sync_with_stdio(0);
	while(std::cin >> n >> m) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 12884kb

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: 0
Accepted
time: 5ms
memory: 12828kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Time Limit Exceeded

input:

17 17
6 10
1 9
14 6
12 13
5 4
15 17
14 15
6 5
10 6
10 11
2 9
9 6
17 15
9 15
4 8
1 4
13 15
13 19
11 10
12 10
10 5
2 8
12 11
8 3
1 7
10 9
8 5
1 5
9 4
8 7
12 10
6 8
13 1
5 8
11 5
10 8
7 7
16 14
9 5
8 1
4 16
10 8
16 15
15 1
13 5
9 3
4 4
9 7
7 2
5 4
5 11
9 14
5 13
1 5
4 5
4 1
4 4
1 1
5 3
3 5
4 1
3 2
5 1
...

output:

8
6
8
2
1
2
7
6
2
6
2
9
10
10
8
10
3
8
7
7
9
10
4
8
6
8
2
2
2
6
6
5
5
4
2
9
4
1
9
6
9
2
6
4
1
2
1
3
6
8
8
6
3
4
7
6
3
8
1
5
3
2
1
5
8
5
7
5
6
7
10
9
3
2
6
7
4
5
6
6
5
1
4
2
4
1
9
7
3
9
4
6
7
5
7
6
1
5
8
5
6
4
5
3
3
7
7
6
9
2
7
3
3
7
10
7
1
2
2
6
6
7
8
7
2
5
1
3
7
2
1
9
9
5
9
5
2
3
1
6
6
3
8
6
1
8
3
...

result: