Submission #1040235

# Submission time Handle Problem Language Result Execution time Memory
1040235 2024-07-31T19:13:53 Z vjudge1 Speedrun (RMI21_speedrun) C++17
100 / 100
117 ms 1204 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sort undefined_function // To use stable_sort instead sort 
#define bpc __builtin_popcount
#define ull unsigned long long
#define ld double
#define ll long long
#define mp make_pair
#define F first
#define S second

#pragma GCC optimize("O3")

#ifdef LOCAL 
        #include "debug.h"
#else 
        #include "speedrun.h"
        #define dbg(...) 0
#endif

using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less_equal<long long>,
    rb_tree_tag, tree_order_statistics_node_update> Tree;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 998244353; //[998244353, 1e9 + 7, 1e9 + 13]
const ld PI = acos(-1);
const ll NROOT = 800;

ll binpow(ll a, ll b, ll _MOD = -1) {
        if (_MOD == -1)
                _MOD = MOD;
        ll res = 1;
        for (; b; b /= 2, a *= a, a %= _MOD)
                if (b & 1) res *= a, res %= _MOD;
        return res;
}

void set_IO(string s) {
#ifndef LOCAL
        string in  = s +  ".in";
        string out = s + ".out";
        freopen(in.c_str(),  "r",  stdin);
        freopen(out.c_str(), "w", stdout);
#endif
}

bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
ll invmod(ll a) {return binpow(a, MOD - 2);}

void assignHints (int subtask , int N, int A[], int B[]);
void speedrun(int subtask , int N, int start );

void setHintLen (int l);
void setHint(int i, int j, bool b);
int getLength ();
bool getHint(int j);
bool goTo(int x);

vector<int> et(1), parent(1001);
vector<vector<int>> G;

void euler_tour(int x, int prt) {
        et.push_back(x);
        if (prt != -1)
                parent[x] = prt;

        for (auto &y : G[x]) {
                if (y == prt)
                        continue;
                euler_tour(y, x);
        }
}

void assignHints(int subtask, int N, int A[], int B[]) {
        setHintLen(20);
        G.resize(N + 1);

        for (int i = 1; i < N; i ++) {
                G[A[i]].push_back(B[i]);
                G[B[i]].push_back(A[i]);
        }

        euler_tour(1, -1);
        et.push_back(1);

        for (int i = 1; i <= N; i ++) {
                for (int j = 1; j <= 10; j ++) 
                        setHint(i, j, (parent[i] & (1 << (j - 1))) > 0);
                for (int j = 1; j <= 10; j ++) 
                        setHint(et[i], j + 10, (et[i + 1] & (1 << (j - 1))) > 0);
        }

        dbg("Assign");
}

pair<int, int> getData() {
        pair<int, int> ans;

        for (int j = 1; j <= 10; j ++) 
                ans.F |= getHint(j) << (j - 1);
        for (int j = 1; j <= 10; j ++) 
                ans.S |= getHint(j + 10) << (j - 1);

        return ans;
}

void speedrun(int subtask, int N, int start) {
        dbg("speed");

        while (start != 1) {
                start = getData().F;
                goTo(start);
        }

        do {
                int next = getData().S;
                while (!goTo(next)) {
                        start = getData().F;
                        goTo(start);

                }
                start = next;
        } while (start != 1);
}

Compilation message

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:19:26: warning: statement has no effect [-Wunused-value]
   19 |         #define dbg(...) 0
      |                          ^
speedrun.cpp:102:9: note: in expansion of macro 'dbg'
  102 |         dbg("Assign");
      |         ^~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:19:26: warning: statement has no effect [-Wunused-value]
   19 |         #define dbg(...) 0
      |                          ^
speedrun.cpp:117:9: note: in expansion of macro 'dbg'
  117 |         dbg("speed");
      |         ^~~
speedrun.cpp: In function 'void set_IO(std::string)':
speedrun.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(in.c_str(),  "r",  stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
speedrun.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(out.c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 105 ms 940 KB Output is correct
2 Correct 90 ms 892 KB Output is correct
3 Correct 103 ms 940 KB Output is correct
4 Correct 97 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 852 KB Output is correct
2 Correct 79 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 684 KB Output is correct
2 Correct 95 ms 684 KB Output is correct
3 Correct 93 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 932 KB Output is correct
2 Correct 117 ms 688 KB Output is correct
3 Correct 110 ms 952 KB Output is correct
4 Correct 94 ms 1144 KB Output is correct
5 Correct 87 ms 700 KB Output is correct
6 Correct 80 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 688 KB Output is correct
2 Correct 89 ms 1200 KB Output is correct
3 Correct 98 ms 684 KB Output is correct
4 Correct 97 ms 700 KB Output is correct
5 Correct 83 ms 848 KB Output is correct
6 Correct 89 ms 1204 KB Output is correct
7 Correct 103 ms 688 KB Output is correct