This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "speedrun.h"
#include <bits/stdc++.h>
//#define int long long
#define pii pair<int, int>
#define ti3 tuple<int, int, int>
#define ti4 tuple<int, int, int, int>
// This is like my secret account; yes it's like that ~ Baek Jiheon, Feel Good (Secret Code)
using namespace std;
vector<int> adjlist[1001];
string toBin(int x){
string ans = "";
while (x!=0){
ans += (x%2)+'0';
x /= 2;
}
while (ans.length() < 10) ans += "0";
return ans;
}
int par[1001], child[1001];
void dfs(int x, int p){
par[x] = p;
for (auto i : adjlist[x]) if (i != p){
child[x] = i;
dfs(i, x);
}
}
void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */
setHintLen(20);
int stNode = 0;
for (int i = 1; i < N; i++){
adjlist[A[i]].push_back(B[i]);
adjlist[B[i]].push_back(A[i]);
}
for (int i = 1; i <= N; i++){
if (adjlist[i].size() == 1) stNode = i;
}
dfs(stNode, 0);
for (int i = 1; i <= N; i++){
string s1 = toBin(par[i]);
string s2 = toBin(child[i]);
for (int j = 0; j < s1.length(); j++){
setHint(i, j+1, s1[j]-'0');
}
for (int j = 0; j < s2.length(); j++){
setHint(i, j+11, s2[j]-'0');
}
}
}
int fromBin(string x){
int p = 1;
int ans = 0;
for (int i = 0; i < x.length(); i++){
ans += (x[i] == '1'? p: 0);
p *= 2;
}
return ans;
}
void speedrun(int subtask, int N, int start) { /* your solution here */
int l = getLength();
while (true){
string b1 = "";
for (int i = 1; i <= 10; i++){
b1 += getHint(i) + '0';
}
int x = fromBin(b1);
if (x == 0) break;
goTo(x);
}
while (true){
string b1 = "";
for (int i = 11; i <= 20; i++){
b1 += getHint(i) + '0';
}
int x = fromBin(b1);
if (x == 0) break;
goTo(x);
}
}
Compilation message (stderr)
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 0; j < s1.length(); j++){
| ~~^~~~~~~~~~~~~
speedrun.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int j = 0; j < s2.length(); j++){
| ~~^~~~~~~~~~~~~
speedrun.cpp: In function 'int fromBin(std::string)':
speedrun.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < x.length(); i++){
| ~~^~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:59:9: warning: unused variable 'l' [-Wunused-variable]
59 | int l = getLength();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |