답안 #847400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847400 2023-09-09T15:24:21 Z TahirAliyev Speedrun (RMI21_speedrun) C++17
100 / 100
139 ms 2184 KB
#include "speedrun.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 2002;
 
int par[MAX];
vector<int> g[MAX];
vector<int> tour;
 
string convert(int a){
    string s = "";
    while(a){
        if(a % 2) s += '1';
        else s += '0'; 
        a /= 2;
    }
    while(s.size() < 10){
        s += '0';
    }
    return s;
}
 
int convert2(string s){
    int a = 0;
    for(int i = 0; i < s.size(); i++){
        a += (1 << i) * (s[i] == '1');
    }
    return a;
}
 
void dfs(int node, int p){
    par[node] = p;
    tour.push_back(node);
    for(int to : g[node]){
        if(to == p) continue;
        dfs(to, node);
    }
}
 
 
void assignHints(int subtask, int N, int A[], int B[]) {
    for(int i = 1; i < N; i++){
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    setHintLen(20);
    dfs(1, 0);
    for(int i = 1; i <= N; i++){
        string s = convert(par[i]);
        for(int j = 1; j <= 10; j++){
            setHint(i, j, (s[j - 1] == '1'));
        }
    }
    for(int i = 1; i <= N; i++){
        if(i == N) continue;
        string s = convert(tour[i]);
        for(int j = 11; j <= 20; j++){
            setHint(tour[i - 1], j, (s[j - 11] == '1'));
        }
    }
    for(int j = 11; j <= 20; j++){
        setHint(tour[N - 1], j, 0);
    }
}   
 
void speedrun(int subtask, int N, int start) {
    int nxt = -1, p = 0;
    while(start != 1){
        string s1 = "";
        for(int j = 1; j <= 10; j++){
            if(getHint(j)){
                s1 += '1';
            }
            else{
                s1 += '0';
            }
        }
        p = convert2(s1);
        goTo(p);
        start = p;
    }
    while(true){
        string s1 = "", s2 = "";
        for(int j = 1; j <= 10; j++){
            if(getHint(j)){
                s1 += '1';
            }
            else{
                s1 += '0';
            }
        }
        for(int j = 11; j <= 20; j++){
            if(getHint(j)){
                s2 += '1';
            }
            else{
                s2 += '0';
            }
        }
        p = convert2(s1);
        if(nxt == -1){
            nxt = convert2(s2);
        }
        if(nxt == 0) break;
        if(goTo(nxt)){
            start = nxt;
            nxt = -1;
        }
        else{
            goTo(p);
            start = p;
        }
    }
}

Compilation message

speedrun.cpp: In function 'int convert2(std::string)':
speedrun.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 1672 KB Output is correct
2 Correct 119 ms 1180 KB Output is correct
3 Correct 119 ms 1420 KB Output is correct
4 Correct 107 ms 2184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 1416 KB Output is correct
2 Correct 102 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 900 KB Output is correct
2 Correct 102 ms 1696 KB Output is correct
3 Correct 106 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 1416 KB Output is correct
2 Correct 105 ms 1696 KB Output is correct
3 Correct 114 ms 1684 KB Output is correct
4 Correct 122 ms 1460 KB Output is correct
5 Correct 122 ms 1664 KB Output is correct
6 Correct 115 ms 1420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 1564 KB Output is correct
2 Correct 112 ms 1420 KB Output is correct
3 Correct 109 ms 1464 KB Output is correct
4 Correct 96 ms 1676 KB Output is correct
5 Correct 104 ms 1676 KB Output is correct
6 Correct 111 ms 1432 KB Output is correct
7 Correct 95 ms 1680 KB Output is correct