Submission #960139

# Submission time Handle Problem Language Result Execution time Memory
960139 2024-04-09T18:01:59 Z tutis Longest Trip (IOI23_longesttrip) C++17
0 / 100
12 ms 444 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(0);
 
std::vector<int> longest_trip(int N, int D)
{
    vector<int>x,y;
    x.push_back(0);
    for(int i=1;i<N;i++){
        if(are_connected({0}, {i})){
            x.push_back(i);
        } else{
            y.push_back(i);
        }
    }
    if(y.size()>0 && !are_connected(x,y)){
        if(x.size()>y.size()){
            return x;
        } else{
            return y;
        }
    }
    if(y.size()>0){
        vector<int>y_;
        for(int i=0;i<N;i++){
            if(find(y.begin(),y.end(),i)==y.end()){
                y_.push_back(i);
            }
        }
        int lo=0;
        int hi=y.size()-1;
        while(lo<hi){
            int m=(lo+hi)/2;
            vector<int>vv;
            for(int i=lo;i<=m;i++){
                vv.push_back(y[i]);
            }
            if(are_connected(vv, y_)){
                hi=m;
            } else{
                lo=m+1;
            }
        }
        swap(y[y.size()-1], y[lo]);
    }
    vector<int>ans = y;
    vector<int>p;
    if(y.size()==0){
        ans.push_back({1});
    }
    for(int i=1;i<N;i++){
        if(find(ans.begin(),ans.end(),i)==ans.end()){
            p.push_back(i);
        }
    }
    while(!p.empty()){
        shuffle(p.begin(),p.end(),rng);
        if(!are_connected({ans.back()}, p)){
            break;
        }
        for(int i: p){
            if(are_connected({ans.back()}, {i})){
                ans.push_back(i);
                p.erase(find(p.begin(),p.end(), i));
            }
        }
    }
    ans.push_back(0);
    for(int i: p){
        ans.push_back(i);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 2 ms 444 KB non-disjoint arrays
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Incorrect 0 ms 424 KB non-disjoint arrays
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB non-disjoint arrays
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB non-disjoint arrays
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB non-disjoint arrays
3 Halted 0 ms 0 KB -