Submission #1040092

# Submission time Handle Problem Language Result Execution time Memory
1040092 2024-07-31T16:02:10 Z vjudge1 Speedrun (RMI21_speedrun) C++17
0 / 100
1 ms 344 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 
        #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);

void assignHints(int subtask, int N, int A[], int B[]) {
        setHintLen(N);

        for (int i = 1; i < N; i ++) {
                setHint(A[i], B[i] - 1, 1);
                setHint(B[i], A[i] - 1, 1);
        }
}

int SIZE = -1;
void dfs(int x, int prt) {
        for (int i = 0; i < SIZE; i ++) {
                if (i + 1 == prt)
                        continue;
                if (getHint(i)) {
                        bool c = goTo(i + 1);
                        if (!c)
                                exit(1);

                        dfs(i + 1, x);
                }
        } 

        bool c = 0;
        if (prt != -1)
                c = goTo(prt);

        if (!c)
                exit(1);
}

void speedrun(int subtask, int N, int start) {
        SIZE = N;

        dfs(start, -1);
}

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

int l = -1, actualNode = -1;
vector<vector<int>> g, hints;

void setHintLen(int x) {
        l = x;
        for (auto &h : hints)
                h.resize(l);
}

void setHint(int i, int j, bool b) {
        hints[i][j] = b; 
}

int getLength() {
        return l;
}

bool getHint(int j) {
        return hints[actualNode][j];
}

bool goTo(int x) {
        bool ok = 0;
        for (auto &y : g[actualNode])
                if (y == x)
                        ok = 1;

        if (ok)
                actualNode = x;
        return ok;
} 

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        int n;
        cin >> n;

        int A[n], B[n];
        g.resize(n + 1);
        hints.resize(n + 1);

        for (int i = 1; i < n; i ++) 
                cin >> A[i];
        for (int i = 1; i < n; i ++)
                cin >> B[i];

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

        int start;
        cin >> start;

        actualNode = start;
        assignHints(1, n, A, B);

        dbg(hints);

        speedrun(1, n, start);

        return 0;
}
#endif

Compilation message

speedrun.cpp: In function 'void set_IO(std::string)':
speedrun.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen(in.c_str(),  "r",  stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
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(out.c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 0 ms 344 KB The length is too large
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB The length is too large
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB The length is too large
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB The length is too large
2 Halted 0 ms 0 KB -