# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043268 |
2024-08-04T07:07:41 Z |
AmirAli_H1 |
Keys (IOI21_keys) |
C++17 |
|
1247 ms |
95860 KB |
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define endl '\n'
#define sep ' '
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define pb push_back
#define Mp make_pair
const int maxn = 3e5 + 7;
const int maxlg = 20;
int n, m;
vector<int> adj[maxn], adjr[maxn];
int val[maxn], arr[maxn];
int p[maxn]; vector<int> ls[maxn];
vector<pair<pii, int>> E;
int mark[maxn], col[maxn], c = 0;
bool M[maxn], ok[maxn]; vector<int> vc;
vector<int> ans;
bool cmp(int i, int j) {
return (val[i] < val[j]);
}
bool is_ok(int u, int c) {
int j = lower_bound(all(ls[u]), c) - ls[u].begin();
return (j < len(ls[u]) && ls[u][j] == c);
}
void dfs(int v) {
mark[v] = 1;
for (int u : adj[v]) {
if (!mark[u]) dfs(u);
}
vc.pb(v);
}
void dfsr(int v) {
mark[v] = 1; col[v] = c;
for (int u : adjr[v]) {
if (!mark[u]) dfsr(u);
}
}
void scc() {
fill(mark, mark + n, 0); vc.clear();
for (int i = 0; i < n; i++) {
if (!mark[i]) dfs(i);
}
reverse(all(vc));
fill(mark, mark + n, 0); c = 0;
for (int i : vc) {
if (!mark[i]) {
dfsr(i); c++;
}
}
}
void fix_edges() {
for (int i = 0; i < n; i++) {
adj[i].clear(); adjr[i].clear();
ls[i].clear(); M[i] = 0;
}
for (int j = 0; j < n; j++) {
int i = arr[j];
ls[p[i]].pb(val[i]);
M[p[i]] = 1;
}
for (auto f : E) {
int u = f.F.F, v = f.F.S, c = f.S;
u = p[u]; v = p[v];
if (u == v) continue;
if (is_ok(u, c)) {
adj[u].pb(v); adjr[v].pb(u);
M[u] = 0;
}
if (is_ok(v, c)) {
adj[v].pb(u); adjr[u].pb(v);
M[v] = 0;
}
}
}
void solve() {
fix_edges();
scc();
for (int i = 0; i < n; i++) p[i] = col[p[i]];
}
vector<int> find_reachable(vector<int> rx, vector<int> ux, vector<int> vx, vector<int> cx) {
n = len(rx); m = len(ux);
for (int i = 0; i < n; i++) val[i] = rx[i];
iota(arr, arr + n, 0); sort(arr, arr + n, cmp);
for (int i = 0; i < m; i++) {
int u = ux[i], v = vx[i], c = cx[i];
E.pb(Mp(Mp(u, v), c));
}
iota(p, p + n, 0);
for (int T = 0; T < maxlg; T++) {
solve();
}
int mn = n; fix_edges();
for (int i = 0; i < n; i++) {
if (!M[i]) continue;
if (len(ls[i]) < mn) mn = len(ls[i]);
}
fill(ok, ok + n, 0);
ans.clear(); ans.resize(n);
for (int i = 0; i < n; i++) {
if (!M[i]) continue;
if (len(ls[i]) == mn) ok[i] = 1;
}
for (int i = 0; i < n; i++) ans[i] = ok[p[i]];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
7 ms |
21596 KB |
Output is correct |
3 |
Correct |
8 ms |
21596 KB |
Output is correct |
4 |
Correct |
9 ms |
21708 KB |
Output is correct |
5 |
Correct |
8 ms |
21600 KB |
Output is correct |
6 |
Correct |
8 ms |
21596 KB |
Output is correct |
7 |
Correct |
7 ms |
21592 KB |
Output is correct |
8 |
Correct |
7 ms |
21616 KB |
Output is correct |
9 |
Correct |
7 ms |
21596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
7 ms |
21596 KB |
Output is correct |
3 |
Correct |
8 ms |
21596 KB |
Output is correct |
4 |
Correct |
9 ms |
21708 KB |
Output is correct |
5 |
Correct |
8 ms |
21600 KB |
Output is correct |
6 |
Correct |
8 ms |
21596 KB |
Output is correct |
7 |
Correct |
7 ms |
21592 KB |
Output is correct |
8 |
Correct |
7 ms |
21616 KB |
Output is correct |
9 |
Correct |
7 ms |
21596 KB |
Output is correct |
10 |
Correct |
12 ms |
21592 KB |
Output is correct |
11 |
Correct |
8 ms |
21584 KB |
Output is correct |
12 |
Correct |
8 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21388 KB |
Output is correct |
14 |
Correct |
9 ms |
21592 KB |
Output is correct |
15 |
Correct |
8 ms |
21596 KB |
Output is correct |
16 |
Correct |
8 ms |
21468 KB |
Output is correct |
17 |
Correct |
9 ms |
21596 KB |
Output is correct |
18 |
Correct |
8 ms |
21596 KB |
Output is correct |
19 |
Correct |
8 ms |
21596 KB |
Output is correct |
20 |
Correct |
8 ms |
21596 KB |
Output is correct |
21 |
Correct |
8 ms |
21668 KB |
Output is correct |
22 |
Correct |
8 ms |
21632 KB |
Output is correct |
23 |
Correct |
8 ms |
21448 KB |
Output is correct |
24 |
Correct |
8 ms |
21592 KB |
Output is correct |
25 |
Correct |
8 ms |
21596 KB |
Output is correct |
26 |
Correct |
9 ms |
21596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
7 ms |
21596 KB |
Output is correct |
3 |
Correct |
8 ms |
21596 KB |
Output is correct |
4 |
Correct |
9 ms |
21708 KB |
Output is correct |
5 |
Correct |
8 ms |
21600 KB |
Output is correct |
6 |
Correct |
8 ms |
21596 KB |
Output is correct |
7 |
Correct |
7 ms |
21592 KB |
Output is correct |
8 |
Correct |
7 ms |
21616 KB |
Output is correct |
9 |
Correct |
7 ms |
21596 KB |
Output is correct |
10 |
Correct |
12 ms |
21592 KB |
Output is correct |
11 |
Correct |
8 ms |
21584 KB |
Output is correct |
12 |
Correct |
8 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21388 KB |
Output is correct |
14 |
Correct |
9 ms |
21592 KB |
Output is correct |
15 |
Correct |
8 ms |
21596 KB |
Output is correct |
16 |
Correct |
8 ms |
21468 KB |
Output is correct |
17 |
Correct |
9 ms |
21596 KB |
Output is correct |
18 |
Correct |
8 ms |
21596 KB |
Output is correct |
19 |
Correct |
8 ms |
21596 KB |
Output is correct |
20 |
Correct |
8 ms |
21596 KB |
Output is correct |
21 |
Correct |
8 ms |
21668 KB |
Output is correct |
22 |
Correct |
8 ms |
21632 KB |
Output is correct |
23 |
Correct |
8 ms |
21448 KB |
Output is correct |
24 |
Correct |
8 ms |
21592 KB |
Output is correct |
25 |
Correct |
8 ms |
21596 KB |
Output is correct |
26 |
Correct |
9 ms |
21596 KB |
Output is correct |
27 |
Correct |
9 ms |
21848 KB |
Output is correct |
28 |
Correct |
10 ms |
21852 KB |
Output is correct |
29 |
Correct |
10 ms |
21848 KB |
Output is correct |
30 |
Correct |
9 ms |
21596 KB |
Output is correct |
31 |
Correct |
10 ms |
21596 KB |
Output is correct |
32 |
Correct |
9 ms |
21600 KB |
Output is correct |
33 |
Correct |
9 ms |
21596 KB |
Output is correct |
34 |
Correct |
9 ms |
21596 KB |
Output is correct |
35 |
Correct |
9 ms |
21596 KB |
Output is correct |
36 |
Correct |
13 ms |
22008 KB |
Output is correct |
37 |
Correct |
8 ms |
21852 KB |
Output is correct |
38 |
Correct |
9 ms |
21904 KB |
Output is correct |
39 |
Correct |
9 ms |
21848 KB |
Output is correct |
40 |
Correct |
11 ms |
21596 KB |
Output is correct |
41 |
Correct |
11 ms |
21852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
7 ms |
21596 KB |
Output is correct |
3 |
Correct |
8 ms |
21596 KB |
Output is correct |
4 |
Correct |
9 ms |
21708 KB |
Output is correct |
5 |
Correct |
8 ms |
21600 KB |
Output is correct |
6 |
Correct |
8 ms |
21596 KB |
Output is correct |
7 |
Correct |
7 ms |
21592 KB |
Output is correct |
8 |
Correct |
7 ms |
21616 KB |
Output is correct |
9 |
Correct |
7 ms |
21596 KB |
Output is correct |
10 |
Correct |
429 ms |
51916 KB |
Output is correct |
11 |
Correct |
585 ms |
79108 KB |
Output is correct |
12 |
Correct |
63 ms |
31492 KB |
Output is correct |
13 |
Correct |
467 ms |
73912 KB |
Output is correct |
14 |
Correct |
216 ms |
95164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
7 ms |
21596 KB |
Output is correct |
3 |
Correct |
8 ms |
21596 KB |
Output is correct |
4 |
Correct |
9 ms |
21708 KB |
Output is correct |
5 |
Correct |
8 ms |
21600 KB |
Output is correct |
6 |
Correct |
8 ms |
21596 KB |
Output is correct |
7 |
Correct |
7 ms |
21592 KB |
Output is correct |
8 |
Correct |
7 ms |
21616 KB |
Output is correct |
9 |
Correct |
7 ms |
21596 KB |
Output is correct |
10 |
Correct |
12 ms |
21592 KB |
Output is correct |
11 |
Correct |
8 ms |
21584 KB |
Output is correct |
12 |
Correct |
8 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21388 KB |
Output is correct |
14 |
Correct |
9 ms |
21592 KB |
Output is correct |
15 |
Correct |
8 ms |
21596 KB |
Output is correct |
16 |
Correct |
8 ms |
21468 KB |
Output is correct |
17 |
Correct |
9 ms |
21596 KB |
Output is correct |
18 |
Correct |
8 ms |
21596 KB |
Output is correct |
19 |
Correct |
8 ms |
21596 KB |
Output is correct |
20 |
Correct |
8 ms |
21596 KB |
Output is correct |
21 |
Correct |
8 ms |
21668 KB |
Output is correct |
22 |
Correct |
8 ms |
21632 KB |
Output is correct |
23 |
Correct |
8 ms |
21448 KB |
Output is correct |
24 |
Correct |
8 ms |
21592 KB |
Output is correct |
25 |
Correct |
8 ms |
21596 KB |
Output is correct |
26 |
Correct |
9 ms |
21596 KB |
Output is correct |
27 |
Correct |
9 ms |
21848 KB |
Output is correct |
28 |
Correct |
10 ms |
21852 KB |
Output is correct |
29 |
Correct |
10 ms |
21848 KB |
Output is correct |
30 |
Correct |
9 ms |
21596 KB |
Output is correct |
31 |
Correct |
10 ms |
21596 KB |
Output is correct |
32 |
Correct |
9 ms |
21600 KB |
Output is correct |
33 |
Correct |
9 ms |
21596 KB |
Output is correct |
34 |
Correct |
9 ms |
21596 KB |
Output is correct |
35 |
Correct |
9 ms |
21596 KB |
Output is correct |
36 |
Correct |
13 ms |
22008 KB |
Output is correct |
37 |
Correct |
8 ms |
21852 KB |
Output is correct |
38 |
Correct |
9 ms |
21904 KB |
Output is correct |
39 |
Correct |
9 ms |
21848 KB |
Output is correct |
40 |
Correct |
11 ms |
21596 KB |
Output is correct |
41 |
Correct |
11 ms |
21852 KB |
Output is correct |
42 |
Correct |
429 ms |
51916 KB |
Output is correct |
43 |
Correct |
585 ms |
79108 KB |
Output is correct |
44 |
Correct |
63 ms |
31492 KB |
Output is correct |
45 |
Correct |
467 ms |
73912 KB |
Output is correct |
46 |
Correct |
216 ms |
95164 KB |
Output is correct |
47 |
Correct |
8 ms |
21596 KB |
Output is correct |
48 |
Correct |
8 ms |
21444 KB |
Output is correct |
49 |
Correct |
8 ms |
21596 KB |
Output is correct |
50 |
Correct |
231 ms |
88372 KB |
Output is correct |
51 |
Correct |
241 ms |
91012 KB |
Output is correct |
52 |
Correct |
640 ms |
59844 KB |
Output is correct |
53 |
Correct |
614 ms |
59116 KB |
Output is correct |
54 |
Correct |
653 ms |
58916 KB |
Output is correct |
55 |
Correct |
387 ms |
53436 KB |
Output is correct |
56 |
Correct |
1247 ms |
88396 KB |
Output is correct |
57 |
Correct |
792 ms |
74300 KB |
Output is correct |
58 |
Correct |
963 ms |
74168 KB |
Output is correct |
59 |
Correct |
639 ms |
69820 KB |
Output is correct |
60 |
Correct |
281 ms |
76984 KB |
Output is correct |
61 |
Correct |
312 ms |
77312 KB |
Output is correct |
62 |
Correct |
254 ms |
65272 KB |
Output is correct |
63 |
Correct |
144 ms |
62580 KB |
Output is correct |
64 |
Correct |
12 ms |
22616 KB |
Output is correct |
65 |
Correct |
10 ms |
22620 KB |
Output is correct |
66 |
Correct |
246 ms |
64736 KB |
Output is correct |
67 |
Correct |
26 ms |
28756 KB |
Output is correct |
68 |
Correct |
47 ms |
33740 KB |
Output is correct |
69 |
Correct |
583 ms |
68548 KB |
Output is correct |
70 |
Correct |
71 ms |
46024 KB |
Output is correct |
71 |
Correct |
214 ms |
95860 KB |
Output is correct |
72 |
Correct |
584 ms |
69744 KB |
Output is correct |
73 |
Correct |
254 ms |
64828 KB |
Output is correct |