/// wa
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 5e4+10;
int was[N];
int mt[N], p[N], tmp;
vector<int> adj[N], g[N];
bool dfs(int x) {
if (was[x] == tmp) return 0;
was[x] = tmp;
for (int to : adj[x]) {
if (mt[to] == -1) {
mt[to] = x;
p[x] = to;
return 1;
}
}
for (int to : adj[x]) {
if (dfs(to)) {
mt[to] = x;
p[x] = to;
return 1;
}
}
return 0;
}
int n, m, k;
bool check(int l, int r) {
for (int i = l; i <= r; ++i) {
for (int to : g[i]) {
adj[to].pb(i);
}
}
fill(p, p+m, -1);
for (int i = 0; i < m; ++i) {
tmp++;
dfs(i);
}
int ok = 1;
for (int i = 0; i < m; ++i) {
if (~p[i]) {
mt[p[i]] = -1;
} else {
ok = 0;
}
}
for (int i = l; i <= r; ++i) {
for (int to : g[i]) {
adj[to].pop_back();
}
}
return ok;
}
void ma1n() {
cin >> n >> m >> k;
for (int u, v; k--;) {
cin >> u >> v;
u--, v--;
g[u].pb(v);
}
int r = 0;
ll ans = 0;
memset(mt, -1, sizeof(mt));
for (int l = 0; l < n; ++l) {
while (r < n && !check(l, r)) {
r++;
}
if (check(l, r)) {
ans += n-r;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
2924 KB |
Output isn't correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
6 |
Correct |
3 ms |
2924 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2924 KB |
Output isn't correct |
8 |
Correct |
3 ms |
2924 KB |
Output is correct |
9 |
Correct |
3 ms |
2924 KB |
Output is correct |
10 |
Correct |
3 ms |
2924 KB |
Output is correct |
11 |
Correct |
3 ms |
2924 KB |
Output is correct |
12 |
Correct |
3 ms |
2924 KB |
Output is correct |
13 |
Correct |
2 ms |
2924 KB |
Output is correct |
14 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
2928 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
2924 KB |
Output isn't correct |
17 |
Correct |
4 ms |
2924 KB |
Output is correct |
18 |
Correct |
3 ms |
2924 KB |
Output is correct |
19 |
Incorrect |
17 ms |
2924 KB |
Output isn't correct |
20 |
Incorrect |
10 ms |
2924 KB |
Output isn't correct |
21 |
Correct |
3 ms |
2924 KB |
Output is correct |
22 |
Incorrect |
2 ms |
2924 KB |
Output isn't correct |
23 |
Correct |
4 ms |
2924 KB |
Output is correct |
24 |
Correct |
5 ms |
2924 KB |
Output is correct |
25 |
Execution timed out |
1572 ms |
3100 KB |
Time limit exceeded |
26 |
Incorrect |
263 ms |
3052 KB |
Output isn't correct |
27 |
Correct |
9 ms |
2924 KB |
Output is correct |
28 |
Incorrect |
6 ms |
2924 KB |
Output isn't correct |
29 |
Correct |
69 ms |
3052 KB |
Output is correct |
30 |
Correct |
24 ms |
3052 KB |
Output is correct |
31 |
Execution timed out |
1590 ms |
3380 KB |
Time limit exceeded |
32 |
Execution timed out |
1584 ms |
3132 KB |
Time limit exceeded |
33 |
Correct |
28 ms |
2924 KB |
Output is correct |
34 |
Incorrect |
28 ms |
2924 KB |
Output isn't correct |
35 |
Correct |
1217 ms |
4016 KB |
Output is correct |
36 |
Correct |
927 ms |
4204 KB |
Output is correct |
37 |
Execution timed out |
1565 ms |
3356 KB |
Time limit exceeded |
38 |
Execution timed out |
1598 ms |
4180 KB |
Time limit exceeded |
39 |
Incorrect |
826 ms |
3180 KB |
Output isn't correct |
40 |
Execution timed out |
1553 ms |
3236 KB |
Time limit exceeded |
41 |
Execution timed out |
1580 ms |
3292 KB |
Time limit exceeded |
42 |
Execution timed out |
1556 ms |
3364 KB |
Time limit exceeded |
43 |
Execution timed out |
1570 ms |
3680 KB |
Time limit exceeded |
44 |
Execution timed out |
1565 ms |
3928 KB |
Time limit exceeded |
45 |
Execution timed out |
1548 ms |
3732 KB |
Time limit exceeded |
46 |
Execution timed out |
1562 ms |
4128 KB |
Time limit exceeded |
47 |
Execution timed out |
1577 ms |
4188 KB |
Time limit exceeded |
48 |
Execution timed out |
1571 ms |
4048 KB |
Time limit exceeded |
49 |
Execution timed out |
1584 ms |
4108 KB |
Time limit exceeded |
50 |
Execution timed out |
1579 ms |
3028 KB |
Time limit exceeded |