Submission #1079617

# Submission time Handle Problem Language Result Execution time Memory
1079617 2024-08-28T18:58:18 Z c2zi6 Longest Trip (IOI23_longesttrip) C++17
0 / 100
939 ms 1628 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 "longesttrip.h"

int n;
VVI gp;
VVI edges;

VI rev(VI a) {
    reverse(all(a));
    return a;
}

VI longest_trip(int N, int D) {
    assert(D == 1);
    n = N;
    gp = VVI(n);
    edges = VVI(n, VI(n));
    replr(i, 0, n-1) {
        replr(j, i+1, n-1) {
            if (are_connected({i}, {j})) {
                gp[i].pb(j);
                gp[j].pb(i);
                edges[i][j] = edges[j][i] = true;
            }
        }
    }
    VI path1;
    VI path2;
    path1.pb(0);
    path2.pb(1);
    replr(u, 2, n-1) {
        if (edges[path1.back()][u]) path1.pb(u);
        else if (edges[path2.back()][u]) path2.pb(u);
        else {
            for (int u : path2) path1.pb(u);
            path2 = VI{u};
        }
    }

    /*if (edges[path2[0]][path1[0]]) {*/
    /*    VI ans;*/
    /*    for (int x : rev(path2)) ans.pb(x);*/
    /*    for (int x : path1) ans.pb(x);*/
    /*    return ans;*/
    /*}*/
    if (edges[path2.back()][path1[0]]) {
        VI ans;
        for (int x : path2) ans.pb(x);
        for (int x : path1) ans.pb(x);
        return ans;
    }
    /* now I know that path2 is also a cycle */
    if (edges[path1.back()][path2[0]]) {
        VI ans;
        for (int x : path1) ans.pb(x);
        for (int x : path2) ans.pb(x);
        return ans;
    }
    /* now I know that path2 is also a cycle */



    if (path1.size() > path2.size()) return path1;
    return path2;
}





# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 207 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 142 ms 592 KB Output is correct
4 Correct 414 ms 580 KB Output is correct
5 Correct 886 ms 1308 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 128 ms 344 KB Output is correct
9 Correct 334 ms 804 KB Output is correct
10 Correct 878 ms 1256 KB Output is correct
11 Correct 939 ms 1224 KB Output is correct
12 Correct 828 ms 1404 KB Output is correct
13 Correct 851 ms 1248 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 6 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 152 ms 592 KB Output is partially correct
4 Partially correct 454 ms 832 KB Output is partially correct
5 Partially correct 837 ms 1004 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 146 ms 344 KB Output is partially correct
9 Partially correct 316 ms 980 KB Output is partially correct
10 Partially correct 876 ms 1628 KB Output is partially correct
11 Partially correct 865 ms 1232 KB Output is partially correct
12 Partially correct 829 ms 1496 KB Output is partially correct
13 Partially correct 806 ms 1172 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Incorrect 3 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -