Submission #840566

# Submission time Handle Problem Language Result Execution time Memory
840566 2023-08-31T13:51:24 Z danikoynov Longest Trip (IOI23_longesttrip) C++17
5 / 100
1000 ms 1784 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 260;
vector < int > adj[maxn];
int used[maxn], edge[maxn][maxn];

int n;
void dfs(int v, int c)
{
    used[v] = c;
    for (int u = 0; u < n; u ++)
    {
        if (edge[v][u] != 1)
            continue;
        if (!used[u])
            dfs(u, c);

    }
}

vector < int > construct(int v, bool done)
{
    for (int i = 0; i < n; i ++)
        used[i] = 0;
    int mx = -1;
    for (int u = 0; u < n; u ++)
    {
        if (edge[v][u] == 1)
        {
            edge[v][u] = 2, mx = u;
            edge[u][v] = 1;
        }
    }

    if (mx == -1)
    {
        vector < int > vec;
        vec.push_back(v);
        return vec;
    }bool split = false;
    if (!done)
    {dfs(mx, 1);

    for (int u = 0; u < n; u ++)
    {
        if (edge[v][u] == 2 && used[u] == 0)
        {
            split = true;
        }
        if (edge[v][u] == 2)
            edge[v][u] = 1;
    }
    }

    if (!split)
    {
        for (int u = 0; u < n; u ++)
        {
            if (edge[v][u])
            {
                edge[v][u] = edge[u][v] = 0;
            }
        }
        vector < int > res = construct(mx, true);
        res.push_back(v);
        return res;
    }

    int dx = -1;
    for (int u = 0; u < n; u ++)
    {
        if (edge[v][u])
        {
            edge[v][u] = edge[u][v] = 0;
            if (u != mx)
                dx = u;
        }
    }

    vector < int > res = construct(mx, true);
    res.push_back(v);
    vector < int > bk = construct(dx, true);
    reverse(bk.begin(), bk.end());
    for (int u : bk)
        res.push_back(u);
    return res;
}
vector<int> longest_trip(int N, int D)
{
    n = N;

    if (D == 3)
    {
        vector < int > r;
        for (int i = 0; i < N; i ++)
            r.push_back(i);
        return r;
    }
    for (int i = 0; i < N; i ++)
        for (int j = 0; j < N; j ++)
        {
            edge[i][j] = edge[j][i] = 0;
        }
        for (int i = 0; i < N; i ++)
            used[i] = 0;
    for (int i = 0; i < N; i ++)
        for (int j = i + 1; j < N; j ++)
    {
        vector < int > a, b;
        a.push_back(i);
        b.push_back(j);
        if (are_connected(a, b))
        {
            adj[i].push_back(j);
            adj[j].push_back(i);
            edge[i][j] = 1;
            edge[j][i] = 1;
        }
    }

    int cp = 0;
    for (int i = 0; i < N; i ++)
    {
        if (!used[i])
            dfs(i, ++ cp);
    }

    if (cp == 2)
    {
        vector < int > a, b;
        for (int i = 0; i < N; i ++)
            if (used[i] == 1)
            a.push_back(i);
        else
            b.push_back(i);
        if (a.size() > b.size())
            return a;
        return b;
    }

    vector < int > res = construct(0, false);
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:101:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  101 |     for (int i = 0; i < N; i ++)
      |     ^~~
longesttrip.cpp:106:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  106 |         for (int i = 0; i < N; i ++)
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 208 KB Output is correct
2 Correct 41 ms 464 KB Output is correct
3 Correct 167 ms 580 KB Output is correct
4 Correct 561 ms 1012 KB Output is correct
5 Correct 891 ms 1664 KB Output is correct
6 Correct 10 ms 320 KB Output is correct
7 Incorrect 5 ms 324 KB Incorrect
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 35 ms 356 KB Output is correct
3 Correct 129 ms 580 KB Output is correct
4 Correct 475 ms 1000 KB Output is correct
5 Correct 971 ms 1784 KB Output is correct
6 Correct 11 ms 316 KB Output is correct
7 Correct 30 ms 336 KB Output is correct
8 Correct 206 ms 512 KB Output is correct
9 Correct 328 ms 788 KB Output is correct
10 Execution timed out 1012 ms 1712 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 328 KB Output is correct
2 Correct 38 ms 364 KB Output is correct
3 Partially correct 165 ms 580 KB Output is partially correct
4 Partially correct 558 ms 1004 KB Output is partially correct
5 Execution timed out 1233 ms 1672 KB Time limit exceeded
6 Halted 0 ms 0 KB -