# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1066824 |
2024-08-20T07:44:11 Z |
정민찬(#11123) |
Speedrun (RMI21_speedrun) |
C++17 |
|
1 ms |
600 KB |
#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
void setHintLen(int l);
void setHint(int i, int j, bool b);
int getLength();
bool getHint(int j);
bool goTo(int x);
vector<int> adj[1010];
vector<int> g[1010];
int par[1010];
void dfs(int x, int p) {
for (auto &y : adj[x]) {
if (y == p) continue;
g[x].push_back(y);
par[y] = x;
dfs(y, x);
}
}
void assignHints(int subtask, int N, int A[], int B[]) {
for (int i=1; i<=N-1; i++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
par[1] = 0;
dfs(1, 0);
setHintLen(20);
for (int i=1; i<=N; i++) {
int fir = 0;
if (!g[i].empty()) fir = g[i][0];
for (int j=0; j<10; j++) {
setHint(i, j, (bool)((1<<j) & fir));
}
}
for (int i=1; i<=N; i++) {
if (g[i].empty()) continue;
for (int j=0; j<g[i].size()-1; j++) {
for (int k=0; k<10; k++) {
setHint(g[i][j], k+10, (bool)((1<<k) & g[i][j+1]));
}
}
for (int k=0; k<10; k++) {
setHint(g[i].back(), k+10, (bool)((1<<k) & par[i]));
}
}
}
int vis[1010];
int dfs2(int x) {
int fir = 0;
int nxt = 0;
for (int i=0; i<10; i++) {
fir ^= (getHint(i) << i);
nxt ^= (getHint(i+10) << i);
}
if (vis[x]) return nxt;
vis[x] = 1;
if (fir == 0) return nxt;
int y = fir;
while (true) {
if (!goTo(y)) break;
y = dfs2(y);
goTo(x);
}
return nxt;
}
void speedrun(int subtask, int N, int start) {
if (N == 1) return;
int fir = 0;
for (int i=0; i<10; i++) {
fir ^= (getHint(i) << i);
}
if (fir == 0) {
for (int i=1; i<=N; i++) {
if (i == start) continue;
int ret = goTo(i);
if (ret) {
start = i;
break;
}
}
}
dfs2(start);
}
/*
static map<int, map<int, bool>> mp;
static int length = -1;
static int queries = 0;
static bool length_set = false;
static int current_node = 0;
static set<int> viz;
static map<int, set<int>> neighbours;
void setHintLen(int l) {
if (length_set) {
cerr << "Cannot call setHintLen twice" << endl;
exit(0);
}
length = l;
length_set = true;
}
void setHint(int i, int j, bool b) {
if (!length_set) {
cerr << "Must call setHintLen before setHint" << endl;
exit(0);
}
mp[i][j] = b;
}
int getLength() { return length; }
bool getHint(int j) { return mp[current_node][j]; }
bool goTo(int x) {
if (neighbours[current_node].find(x) == end(neighbours[current_node])) {
++queries;
return false;
} else {
viz.insert(current_node = x);
return true;
}
}
int main() {
int N;
cin >> N;
int a[N], b[N];
for (int i = 1; i < N; ++i) {
cin >> a[i] >> b[i];
neighbours[a[i]].insert(b[i]);
neighbours[b[i]].insert(a[i]);
}
assignHints(1, N, a, b);
if (!length_set) {
cerr << "Must call setHintLen at least once" << endl;
exit(0);
}
cin >> current_node;
viz.insert(current_node);
speedrun(1, N, current_node);
if (viz.size() < N) {
cerr << "Haven't seen all nodes" << endl;
exit(0);
}
cerr << "OK; " << queries << " incorrect goto's" << endl;
return 0;
}
*/
Compilation message
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:41:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j=0; j<g[i].size()-1; j++) {
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Invalid bit index for setHint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Invalid bit index for setHint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Invalid bit index for setHint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Invalid bit index for setHint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Invalid bit index for setHint |
2 |
Halted |
0 ms |
0 KB |
- |