Submission #1025029

# Submission time Handle Problem Language Result Execution time Memory
1025029 2024-07-16T14:25:40 Z c2zi6 Toy Train (IOI17_train) C++14
16 / 100
7 ms 3644 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "train.h"

struct SCCF {
    int n;
    VVI gpa;
    VVI trans;
    VI vis;

    VVI comp;
    VI group;
    VI order;
    void dfs1(int u) {
        vis[u] = true;
        for (int v : gpa[u]) if (!vis[v]) dfs1(v);
        order.pb(u);
    }
    void dfs2(int u) {
        comp.back().pb(u);
        group[u] = comp.size()-1;
        vis[u] = true;
        for (int v : trans[u]) if (!vis[v]) dfs2(v);
    }

    tuple<VVI, VVI, VI, VI> operator()(VVI& GPA) {
        gpa = GPA;
        n = gpa.size();
        trans = VVI(n);
        rep(u, n) for (int v : gpa[u]) trans[v].pb(u);

        vis = VI(n);
        rep(u, n) if (!vis[u]) dfs1(u);
        reverse(all(order));

        vis = VI(n);
        group = VI(n);
        comp = VVI();
        for (int u : order) if (!vis[u]) {
            comp.pb(VI());
            dfs2(u);
        }

        VVI gpb(comp.size());
        VI cycle(comp.size());
        rep(u, n) for (int v : gpa[u]) if (group[u] != group[v]) {
            gpb[group[u]].pb(group[v]);
        } else cycle[group[u]] = true;
        return make_tuple(gpb, comp, group, cycle);
    }
} SCC;

namespace TEST1 {
    bool check(VI U, VI V) {
        rep(i, U.size()) if (V[i] != U[i] && V[i] != U[i]+1) return false;
        return true;
    }
    VI solve(VVI gp, VI owner, VI charge) {
        int n = gp.size();
        VI ans(n);
        reprl(u, n-1, 0) {
            if (gp[u].size() == 2) {
                if (owner[u] == 1) {
                    ans[u] = 0;
                    if (charge[u] == 1) ans[u] = 1;
                    else for (int v : gp[u]) if (v != u) {
                        if (ans[v] == 1) ans[u] = 1;
                    }
                } else {
                    ans[u] = 1;
                    if (charge[u] == 0) ans[u] = 0;
                    else for (int v : gp[u]) if (v != u) {
                        if (ans[v] == 0) ans[u] = 0;
                    }
                }
            } else if (gp[u].size()) {
                if (gp[u][0] == u) {
                    ans[u] = (charge[u]);
                } else {
                    ans[u] = ans[gp[u][0]];
                }
            }
        }
        return ans;
    }
};
namespace TEST2 {
};
namespace TEST3 {
    bool check(VI owner) {
        for (int x : owner) if (x == 0) return false;
        return true;
    }
    VI solve(VVI GP, VI OWNER, VI charge) {
        int n = GP.size();
        auto[gp, comp, group, cycle] = SCC(GP);
        int g = gp.size();

        /*rep(u, g) {*/
        /*    cout << u << ": ";*/
        /*    for (int x : comp[u]) cout << x << " ";*/
        /*    cout << "is cycle: " << cycle[u];*/
        /*    cout << endl;*/
        /*} cout << endl;*/
        /*rep(u, g) for (int v : gp[u]) {*/
        /*    cout << u << " " << v << endl;*/
        /*}*/

        VI ansg(g);
        rep(u, n) if (charge[u] && cycle[group[u]]) {
            ansg[group[u]] = true;
        }

        reprl(u, g-1, 0) {
            for (int v : gp[u]) {
                ansg[u] |= ansg[v];
            }
        }

        VI ans(n);
        rep(u, n) ans[u] = ansg[group[u]];
        return ans;
    }
};
namespace TEST4 {
};

VI who_wins(VI owner, VI charge, VI U, VI V) {
    int n = owner.size();
    int m = U.size();
    VVI gp(n);
    rep(i, m) gp[U[i]].pb(V[i]);
    if (TEST1::check(U, V)) return TEST1::solve(gp, owner, charge);
    if (TEST3::check(owner)) return TEST3::solve(gp, owner, charge);
	return {3, 1, 4};
}


Compilation message

train.cpp: In function 'VI TEST3::solve(VVI, VI, VI)':
train.cpp:125:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  125 |         auto[gp, comp, group, cycle] = SCC(GP);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 3 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1088 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3644 KB Output is correct
2 Correct 6 ms 3368 KB Output is correct
3 Correct 6 ms 3392 KB Output is correct
4 Correct 6 ms 2368 KB Output is correct
5 Correct 6 ms 2520 KB Output is correct
6 Correct 7 ms 2624 KB Output is correct
7 Correct 7 ms 2344 KB Output is correct
8 Correct 6 ms 2596 KB Output is correct
9 Correct 7 ms 2380 KB Output is correct
10 Correct 6 ms 2376 KB Output is correct
11 Correct 7 ms 2384 KB Output is correct
12 Correct 7 ms 3280 KB Output is correct
13 Correct 7 ms 2468 KB Output is correct
14 Correct 6 ms 2348 KB Output is correct
15 Correct 7 ms 2368 KB Output is correct
16 Correct 6 ms 2520 KB Output is correct
17 Correct 7 ms 2364 KB Output is correct
18 Correct 5 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1256 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1372 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 3 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1088 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Incorrect 0 ms 348 KB WA in grader: Wrong returned array size
13 Halted 0 ms 0 KB -