답안 #1006875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006875 2024-06-24T09:27:44 Z edogawa_something 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
763 ms 848 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define pb push_back
#define F first 
#define S second 
#define all(v) v.begin(),v.end()
const int M=1010;
const ll inf=1e18;
struct dsu{
    ll sz[M],pa[M];
    void init(ll x){
        for(int i=0;i<=x;i++)
        pa[i]=i,sz[i]=1;
    }
    ll get(ll x){
        if(x==pa[x])
        return x;
        return pa[x]=get(pa[x]);
    }
    void unite(ll x,ll y){
        x=get(x),y=get(y);
        if(x==y)
        return;
        if(sz[x]<sz[y])
        swap(x,y);
        pa[y]=x;
        sz[x]+=sz[y];
    }
    bool same(ll x,ll y){
        return (get(x)==get(y));
    }
}d;
ll n;
bool edge[M][M],vis[M];
bool used[M];
std::vector<int> longest_trip(int N, int D)
{
    n=N;
    d.init(n);
    vector<int>ans;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            edge[i][j]=edge[j][i]=are_connected({i},{j});
        }
    }
    for(int i=0;i<n;i++){
        vii v;
        for(int j=0;j<n;j++){
            if(j==i)
            continue;
            else if(!edge[i][j]){
                v.pb(j);
            }
        }   
        for(int j=0;j<ll(v.size())-1;j++)
        d.unite(v[j],v[j+1]);
        for(auto it:v)
        used[it]=1;
    }
    bool chk=1;
    for(int i=0;i<n;i++){
        if(used[i])
        chk=0;
    }
    if(chk){
        for(int i=0;i<n;i++){
            ans.pb(i);
        }
        return ans;
    }
    ll last=-1;
    vii v1,v2;
    for(int i=0;i<n;i++){
        if(used[i]){
            if(last==-1){
                last=i;
                v1.pb(i);
            }
            else if(d.same(i,last))
            v1.pb(i);
            else
            v2.pb(i);
        }
        else
        v2.pb(i);
    }
    bool c=0;
    for(auto it:v1){
        for(auto itt:v2){
            if(edge[it][itt]){
            vis[it]=vis[itt]=1;
            c=1;
            break;
            }
        }
        if(c)
        break;
    }
    if(!c){
        if(v1.size()<v2.size())
        swap(v1,v2);
        for(auto it:v1)
        ans.pb(it);
        return ans;
    }
    ll x=0;
    for(auto it:v1){
        if(!vis[it])
        ans.pb(it);
        else
        x=it;
    }
    ans.pb(x);
    for(auto it:v2){
        if(vis[it])
        ans.pb(it);
    }
    for(auto it:v2){
        if(!vis[it])
        ans.pb(it);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 178 ms 600 KB Incorrect
3 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 Correct 136 ms 344 KB Output is correct
4 Correct 339 ms 344 KB Output is correct
5 Correct 763 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 132 ms 344 KB Output is correct
4 Correct 369 ms 344 KB Output is correct
5 Correct 700 ms 696 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 147 ms 344 KB Output is correct
4 Correct 340 ms 344 KB Output is correct
5 Correct 735 ms 688 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 32 ms 344 KB Output is correct
3 Partially correct 128 ms 344 KB Output is partially correct
4 Partially correct 347 ms 340 KB Output is partially correct
5 Partially correct 733 ms 692 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -