Submission #538945

#TimeUsernameProblemLanguageResultExecution timeMemory
538945ryangohcaSpeedrun (RMI21_speedrun)C++17
8 / 100
115 ms876 KiB
#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; } return ans; } void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */ setHintLen(20); int midNode = 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() > 2) midNode = i; } string s = toBin(midNode); for (int i = 1; i <= N; i++){ if (i == midNode) continue; for (int j = 0; j < s.length(); j++){ setHint(i, j+1, s[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(); string b = ""; for (int i = 1; i <= 20; i++){ b += getHint(i) + '0'; } int x = fromBin(b); if (x != 0) goTo(x); else x = start; for (int i = 1; i <= N; i++){ if (i != x){ goTo(i); goTo(x); } } }

Compilation message (stderr)

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int j = 0; j < s.length(); j++){
      |                         ~~^~~~~~~~~~~~
speedrun.cpp: In function 'int fromBin(std::string)':
speedrun.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < x.length(); i++){
      |                     ~~^~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:46:9: warning: unused variable 'l' [-Wunused-variable]
   46 |     int l = getLength();
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...