답안 #960830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960830 2024-04-11T05:53:54 Z 12345678 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
773 ms 2168 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/2) m=1;
        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/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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 25 ms 600 KB Output is correct
3 Correct 127 ms 972 KB Output is correct
4 Correct 338 ms 1548 KB Output is correct
5 Correct 773 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 596 KB Output is correct
2 Correct 29 ms 344 KB Output is correct
3 Correct 144 ms 344 KB Output is correct
4 Correct 358 ms 992 KB Output is correct
5 Correct 731 ms 1908 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 119 ms 624 KB Output is correct
4 Correct 384 ms 1160 KB Output is correct
5 Correct 739 ms 1892 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Partially correct 135 ms 1112 KB Output is partially correct
4 Partially correct 347 ms 1304 KB Output is partially correct
5 Partially correct 735 ms 1644 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -