QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21807#2832. Graph TheoryCCPSDCGK#WA 45ms5608kbC++202.4kb2022-03-08 15:56:252022-05-08 04:05:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:05:54]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:5608kb
  • [2022-03-08 15:56:25]
  • 提交

answer

#include<map>
#include<set>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
#define mkp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define fs fflush(stdout)
#define ump unordered_map
#define pq priority_queue
#define clz __builtin_clz
#define ctz __builtin_ctz
#define space putchar(' ')
#define enter putchar('\n')
#define sz(x) (int)x.size()
#define np next_permutation
#define clzl __builtin_clzll
#define par __builtin_parity
#define ctzl __builtin_ctzll
#define ppc __builtin_popcount
#define parl __builtin_parityll
#define all(x) x.begin(),x.end()
#define ppcl __builtin_popcountll
#define ms(x,y) memset(x,y,sizeof(x))
#define debug(x) cerr<<#x<<"= "<<(x)<<'\n'
template<class T> inline T &read(T &x){
	x=0;int f=1;char ch=getchar();
	while(ch<48||ch>57){if(ch=='-') f=-f;ch=getchar();}
	while(ch>=48&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*=f;
}
template<class T> inline void print(T x){
	static char buf[40];static int cnt=0;
	if(x<0) putchar(45),x=-x;
	do buf[++cnt]=x%10^48;while(x/=10);
	do putchar(buf[cnt--]);while(cnt);
}
#define mod 998244353
#define inf 0x3f3f3f3f
#define fpi freopen("","r",stdin)
#define fpo freopen("","w",stdout)
pair<int,int> p[200005];
int sum[200005];
inline void add(int l,int r){if(l>r) sum[1]++;sum[l]++,sum[r]--;}
bool check(int x,int n,int m){
	int i;
	for(i=1;i<=m;i++){
		if(p[i].second-p[i].first>x) add(p[i].second,p[i].first);
		if(n+p[i].first-p[i].second>x) add(p[i].first,p[i].second);
	}
	for(i=2;i<=n;i++) sum[i]+=sum[i-1];
	for(i=1;i<=n;i++) if(!sum[i]) return 1;return 0;
}
void solve(int n,int m){
	int l=0,r=n,ans,i;
	for(i=1;i<=n;i++) sum[i]=0; 
	for(i=1;i<=m;i++){
		read(p[i].first),read(p[i].second);
		if(p[i].first>p[i].second) p[i].first^=p[i].second^=p[i].first^=p[i].second;
		l=max(l,min(p[i].second-p[i].first,n+p[i].first-p[i].second));
	}
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid,n,m)) ans=mid,r=mid-1;else l=mid+1;
	}print(ans),enter;
}
int main(){
	int n,m;
	while(cin>>n>>m) solve(n,m);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5608kb

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: 1ms
memory: 3572kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 45ms
memory: 3568kb

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:

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

result:

wrong answer 1st lines differ - expected: '8', found: '12'