Submission #961073

# Submission time Handle Problem Language Result Execution time Memory
961073 2024-04-11T13:28:22 Z 12345678 Longest Trip (IOI23_longesttrip) C++17
5 / 100
841 ms 2096 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=305;

int qrs[nx][nx], vs[nx], m, cnt, u, v;
vector<int> d[nx];

int query(int i, int j)
{
    if (i>j) swap(i, j);
    return qrs[i][j];
}

void dfs(int u)
{
    vs[u]=1;
    cnt++;
    for (auto v:d[u]) if (!vs[v]) dfs(v);
}

std::vector<int> longest_trip(int N, int D)
{
    for (int i=0; i<N; i++) d[i].clear(), vs[i]=0;
    for (int i=0; i<N; i++) for (int j=i+1; j<N; j++) qrs[i][j]=are_connected(vector<int> {i}, vector<int> {j});
    for (int i=0; i<N; i++) for (int j=0; j<N; j++) if (query(i, j)) d[i].push_back(j);
    cnt=0;
    dfs(0);
    vector<int> res;
    if (cnt!=N)
    {
        if (cnt>=N-cnt) m=1;
        else m=0;
        for (int i=0; i<N; i++)
        {
            if (vs[i]&&m) res.push_back(i);
            if (!vs[i]&&!m) res.push_back(i);
        }
        return res;
    }
    pair<int, int> mn={INT_MAX, 0};
    for (int i=0; i<N; i++) mn=min(mn, {d[i].size(), i});
    //cout<<"here "<<mn.first<<' '<<mn.second<<'\n';
    if (mn.first>=((N-1)/2))
    {
        for (int i=0; i<N; i++) vs[i]=0;
        int cur=mn.second;
        while (1)
        {
            res.push_back(cur);
            vs[cur]=1;
            bool can=0;
            for (auto v:d[u]) if (!vs[v]) can=1, cur=v;
            if (!can) break;
        }
        return res;
    }
    else
    {
        for (int i=0; i<N; i++) if (!query(i, mn.second)&&i!=mn.second) res.push_back(i);
        return res;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 31 ms 600 KB Output is correct
3 Correct 158 ms 604 KB Output is correct
4 Correct 428 ms 1256 KB Output is correct
5 Correct 817 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 30 ms 344 KB Output is correct
3 Correct 157 ms 1112 KB Output is correct
4 Correct 401 ms 1272 KB Output is correct
5 Correct 811 ms 1640 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 25 ms 456 KB Output is correct
3 Correct 167 ms 856 KB Output is correct
4 Correct 348 ms 1736 KB Output is correct
5 Correct 689 ms 1432 KB Output is correct
6 Incorrect 1 ms 768 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 34 ms 856 KB Output is correct
3 Partially correct 148 ms 1232 KB Output is partially correct
4 Partially correct 399 ms 1368 KB Output is partially correct
5 Partially correct 841 ms 2096 KB Output is partially correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -