QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107954#2832. Graph Theoryl1924365846WA 30ms3744kbC++173.1kb2023-05-23 11:10:482023-05-23 11:10:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 11:10:49]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:3744kb
  • [2023-05-23 11:10:48]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define int ll
#define ms(a,b) memset((a),(b),sizeof(a))
#define mc(a,b) memcpy((a),(b),sizeof(a))
#define PI acos(-1)
#define ssin(x) sin(x*PI/180.00)
#define ccos(x) cos(x*PI/180.00)
#define ttan(X) tan(x*PI/180.00)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define IOS ios::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sii(x, y) scanf("%d %d",&x, &y)
#define siii(x, y, z) scanf("%d %d %d",&x, &y, &z)
#define siiii(x, y, z, w) scanf("%d %d %d %d",&x, &y, &z, &w)
#define sl(x) scanf("%lld",&x)
#define sll(x, y) scanf("%lld %lld",&x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld",&x, &y, &z)
#define sllll(x, y, z, w) scanf("%lld %lld %lld %lld",&x, &y, &z, &w)
#define pr(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define sd(x) scanf("%lf",&x)
#define sdd(x, y) scanf("%lf %lf",&x, &y)
#define sddd(x, y, z) scanf("%lf %lf %lf",&x, &y, &z)
#define sdddd(x, y, z, w) scanf("%lf %lf %lf %lf",&x, &y, &z, &w)
#define fi first
#define se second
#define pb push_back
#define mk make_mair

using namespace std;

typedef unsigned long long ull;

typedef pair<int, int> PII;

const int mod = 998244353;

const int P = 131;

const int N = 1e5 + 10, M = 3e6 + 10;

const int inf = 0x3f3f3f3f;

const ll lnf = 9e18;

const double eps = 1e-6;

int n, m;
struct F {
	int a, b, len;
} f[N];
map<int, int> ma;

bool cmp (F x, F y) {
	return x.len < y.len;
}

void solve() {
	while (~scanf ("%lld %lld", &n, &m) ) {
		ma.clear();
		int res = 0, cnt = 0;

		for (int i = 0; i < m; i ++) {
			int x, y;
			sll (x, y);

			if (x <= y) {

				if (y - x < n - (y - x) ) {
					f[i] = {x, y, y - x};
				}
				else {
					f[i] = {y - 1, x - 1, n - (y - x) };
				}
			}
			else {
				if (y - x < n - (y - x) ) {
					f[i] = {y - 1, x - 1, y - x};
				}
				else {
					f[i] = {x, y, n - (y - x) };
				}
			}

			res = max (res, f[i].len);
		}

		sort (f, f + m, cmp);

		for (int i = 0; i < m; i ++) {
			if (f[i].a > f[i].b) {
				for (int j = f[i].a; j < f[i].b + n; j ++) {
					if (!ma.count (j % n) ) {
						ma[j % n] = f[i].len;
						cnt++;
					}
				}
			}
			else {
				for (int j = f[i].a; j < f[i].b; j ++) {
					if (!ma.count (j % n) ) {
						ma[j % n] = f[i].len;
						cnt++;
					}
				}
			}

			if (cnt == n)
				break;
		}

//		cout<<cnt<<endl;

		if (cnt != n) {
			for (int i = 1; i <= n; i ++) {
				if (!ma.count (i) ) {
					printf ("%lld\n", res);
					break;
				}
			}
		}
		else {
			int cc = 0;

			for (int i = 1; i <= n; i ++) {
				cc = max (cc, ma[i]);
			}

			printf ("%lld\n", n - cc);
		}
	}
}

signed main() {
	//	IOS;
	//	cin.tie (0);
	//	cout.tie (0);
	int T (1);
	//	sl (T);

	while ( T-- ) {
		solve();
	}

	return 0;
}

/*
3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 3532kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 30ms
memory: 3508kb

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
12
4
1
3
10
9
1
9
3
14
10
9
10
16
3
13
7
9
9
13
9
3
7
8
3
2
1
9
7
9
5
7
2
16
4
2
15
10
12
3
7
4
2
2
2
2
6
13
8
10
4
11
7
8
4
8
2
6
4
3
1
7
8
8
7
8
7
9
12
11
6
3
8
2
8
5
6
9
6
1
4
3
5
1
9
11
5
10
2
1
7
6
10
11
2
10
13
4
7
3
6
4
7
5
13
5
6
2
14
4
2
4
15
8
2
1
3
6
6
7
14
7
3
7
1
5
8
0
2
18
11
8
4
6...

result:

wrong answer 3rd lines differ - expected: '8', found: '12'