Submission #1075638

# Submission time Handle Problem Language Result Execution time Memory
1075638 2024-08-26T08:12:32 Z c2zi6 Longest Trip (IOI23_longesttrip) C++17
5 / 100
901 ms 592 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"

bool samecomp(VI a, VI b) {
    return !are_connected(a, b);
}

VI longest_trip(int N, int D) {
    if (D == 3) {
        VI ans;
        rep(u, N) ans.pb(u);
        return ans;
    } else if (D == 2) {
        int n = N;
        VI group(n, -1);
        int last = 0;
        rep(u, n) if (group[u] == -1) {
            group[u] = last;
            rep(v, n) if (group[v] == -1) {
                if (samecomp({u}, {v})) group[v] = last;
            }
            last++;
        }
        VVI comp(last);
        rep(u, n) comp[group[u]].pb(u);

        int prev = -1;

        VI ans;
        rep(_, 2) {
            rep(i, last) {
                if (comp[i].size() && i != prev) {
                    ans.pb(comp[i].back());
                    comp[i].pop_back();
                    prev = i;
                }
            }
        }
        return ans;
        /*for (VI vec : comp) {*/
        /*    for (int x : vec) cout << x << " ";*/
        /*    cout << endl;*/
        /*}*/
    }
    return {};
}




# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 153 ms 344 KB Output is correct
4 Correct 416 ms 432 KB Output is correct
5 Correct 901 ms 592 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -