QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107949 | #2832. Graph Theory | l1924365846 | WA | 29ms | 3764kb | C++17 | 3.0kb | 2023-05-23 11:00:35 | 2023-05-23 11:00:39 |
Judging History
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 (y - x < n - (y - x) ) {
f[i] = {x, y, 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: 2ms
memory: 3764kb
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: 3556kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 29ms
memory: 3584kb
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:
17 13 16 5 1 4 14 13 4 12 4 18 14 20 18 16 6 17 7 15 19 18 10 16 13 16 2 5 1 13 12 10 17 5 4 19 9 3 19 13 20 3 12 9 3 2 2 6 13 17 16 12 6 13 12 12 6 12 3 11 6 2 1 9 16 10 15 8 7 6 20 11 7 3 12 14 9 15 13 14 9 1 9 4 9 1 19 15 7 19 11 13 14 10 17 12 3 11 17 11 8 5 11 7 9 15 14 13 18 5 15 5 2 17 20 12 ...
result:
wrong answer 1st lines differ - expected: '8', found: '17'