#include "Joi.h"
#include <vector>
#include <map>
using namespace std;
static vector<vector<int>> adj;
static vector<int> ord;
static vector<int> vis;
static vector<bool> seen;
static void dfs(int at) {
seen[at] = true;
vis.push_back(at);
ord.push_back(at);
for (int it : adj[at]) {
if (seen[it]) continue;
dfs(it);
ord.push_back(at);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
adj.resize(N);
seen.resize(N);
for (int i = 0; i < M; i ++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
dfs(0);
ord.pop_back();
for(int i = 0; i < N; i++){
int b = (i % 60);
MessageBoard(vis[i], (X >> b) & 1);
}
}
#include "Ioi.h"
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
static vector<vector<int>> adj;
static vector<int> ord;
static vector<int> vis;
static vector<bool> seen;
static void dfs(int at) {
seen[at] = true;
vis.push_back(at);
ord.push_back(at);
for (int it : adj[at]) {
if (seen[it]) continue;
dfs(it);
ord.push_back(at);
}
}
static map<int, int> bits;
static map<int, int> bit;
static set<int> tovis;
void dfs2(int at) {
cerr << "at " << at << " with bit " << bit[at] << endl;
tovis.erase(at);
for (int it : adj[at]) {
if (!tovis.count(it)) continue;
bits[bit[it]] = Move(it);
dfs2(it);
if (bits.size() == 60) break;
Move(at);
}
cerr << "backtrack " << at << endl;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
adj.resize(N);
seen.resize(N);
for (int i = 0; i < M; i ++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
dfs(0);
ord.pop_back();
for(int i = 0; i < N; i++){
int b = (i % 60);
bit[vis[i]] = b;
}
bits[bit[P]] = V;
map<int, int> occ;
for (int i = ord.size() - 1; i >= 0; --i) occ[ord[i]] = i;
int idx = find(vis.begin(), vis.end(), P) - vis.begin();
cerr << "i am at idx " << idx << " vert " << P << endl;
int lo = max(0, idx - 59);
int hi = lo + 59;
int at1 = occ[vis[lo]], at2 = occ[vis[hi]];
for (int nlo = max(0, idx - 59); nlo < min(N - 60, idx); ++nlo) {
int nhi = nlo + 60;
int nat1 = occ[vis[nlo]], nat2 = occ[vis[nhi]];
if (nat2 - nat1 < at2 - at1) {
at1 = nat1, at2 = nat2;
}
}
cerr << "go for " << at1 << " to " << at2 << endl;
for (int v = at1; v <= at2; ++v) tovis.insert(ord[v]);
dfs2(P);
cerr << "got " << bits.size() << endl;
//while (bits.size() != 60) {
// at = (at + d + ord.size()) % ord.size();
// cerr << "go to " << ord[at] << " get bit " << bit[ord[at]] << endl;
// bits[bit[ord[at]]] = Move(ord[at]);
//}
long long X = 0;
for (int i = 0; i < 60; ++i) {
X |= (long long)bits[i] << i;
}
return X;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
624 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
624 KB |
Output is correct |
7 |
Correct |
3 ms |
748 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
696 KB |
Output is correct |
10 |
Correct |
3 ms |
628 KB |
Output is correct |
11 |
Correct |
6 ms |
1048 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
3 ms |
616 KB |
Output is correct |
14 |
Correct |
3 ms |
748 KB |
Output is correct |
15 |
Correct |
3 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
620 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
5288 KB |
Output is correct |
2 |
Correct |
34 ms |
5288 KB |
Output is correct |
3 |
Correct |
34 ms |
5248 KB |
Output is correct |
4 |
Correct |
22 ms |
3904 KB |
Output is correct |
5 |
Correct |
24 ms |
4492 KB |
Output is correct |
6 |
Correct |
22 ms |
4152 KB |
Output is correct |
7 |
Correct |
23 ms |
4152 KB |
Output is correct |
8 |
Correct |
23 ms |
4332 KB |
Output is correct |
9 |
Correct |
24 ms |
4400 KB |
Output is correct |
10 |
Correct |
20 ms |
3828 KB |
Output is correct |
11 |
Correct |
23 ms |
3844 KB |
Output is correct |
12 |
Correct |
20 ms |
3540 KB |
Output is correct |
13 |
Correct |
20 ms |
3548 KB |
Output is correct |
14 |
Correct |
22 ms |
3628 KB |
Output is correct |
15 |
Correct |
23 ms |
3896 KB |
Output is correct |
16 |
Correct |
22 ms |
3796 KB |
Output is correct |
17 |
Correct |
22 ms |
3912 KB |
Output is correct |
18 |
Correct |
22 ms |
3864 KB |
Output is correct |
19 |
Correct |
22 ms |
3888 KB |
Output is correct |
20 |
Correct |
61 ms |
4696 KB |
Output is correct |
21 |
Correct |
49 ms |
4576 KB |
Output is correct |
22 |
Correct |
24 ms |
4156 KB |
Output is correct |
23 |
Correct |
23 ms |
4312 KB |
Output is correct |
24 |
Correct |
22 ms |
4224 KB |
Output is correct |
25 |
Correct |
23 ms |
4144 KB |
Output is correct |
26 |
Correct |
26 ms |
4388 KB |
Output is correct |
27 |
Correct |
22 ms |
4368 KB |
Output is correct |
28 |
Correct |
24 ms |
4324 KB |
Output is correct |
29 |
Correct |
20 ms |
4004 KB |
Output is correct |
30 |
Correct |
22 ms |
4152 KB |
Output is correct |
31 |
Correct |
2 ms |
624 KB |
Output is correct |
32 |
Correct |
2 ms |
616 KB |
Output is correct |
33 |
Correct |
3 ms |
620 KB |
Output is correct |
34 |
Correct |
3 ms |
620 KB |
Output is correct |
35 |
Correct |
2 ms |
620 KB |
Output is correct |
36 |
Correct |
2 ms |
632 KB |
Output is correct |
37 |
Correct |
2 ms |
616 KB |
Output is correct |
38 |
Correct |
1 ms |
488 KB |
Output is correct |
39 |
Correct |
2 ms |
492 KB |
Output is correct |
40 |
Correct |
2 ms |
616 KB |
Output is correct |
41 |
Correct |
2 ms |
616 KB |
Output is correct |
42 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
616 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
5 ms |
1156 KB |
Output is correct |
5 |
Correct |
5 ms |
1284 KB |
Output is correct |
6 |
Correct |
5 ms |
1156 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1284 KB |
Output is correct |
9 |
Correct |
18 ms |
4972 KB |
Output is correct |
10 |
Correct |
18 ms |
4912 KB |
Output is correct |
11 |
Correct |
18 ms |
4920 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
2 ms |
616 KB |
Output is correct |
15 |
Correct |
1 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5292 KB |
Output is correct |
2 |
Partially correct |
35 ms |
5432 KB |
Partially correct |
3 |
Partially correct |
34 ms |
5304 KB |
Partially correct |
4 |
Correct |
22 ms |
3888 KB |
Output is correct |
5 |
Correct |
23 ms |
4556 KB |
Output is correct |
6 |
Partially correct |
23 ms |
4412 KB |
Partially correct |
7 |
Correct |
23 ms |
4284 KB |
Output is correct |
8 |
Correct |
23 ms |
4156 KB |
Output is correct |
9 |
Correct |
22 ms |
4156 KB |
Output is correct |
10 |
Correct |
20 ms |
3860 KB |
Output is correct |
11 |
Correct |
20 ms |
3876 KB |
Output is correct |
12 |
Correct |
20 ms |
3508 KB |
Output is correct |
13 |
Correct |
20 ms |
3476 KB |
Output is correct |
14 |
Correct |
20 ms |
3696 KB |
Output is correct |
15 |
Correct |
23 ms |
3860 KB |
Output is correct |
16 |
Correct |
22 ms |
3892 KB |
Output is correct |
17 |
Partially correct |
22 ms |
3864 KB |
Partially correct |
18 |
Correct |
22 ms |
3912 KB |
Output is correct |
19 |
Correct |
22 ms |
3804 KB |
Output is correct |
20 |
Incorrect |
49 ms |
4616 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
5320 KB |
Output is correct |
2 |
Correct |
35 ms |
5180 KB |
Output is correct |
3 |
Incorrect |
35 ms |
5304 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |