Submission #848221

# Submission time Handle Problem Language Result Execution time Memory
848221 2023-09-11T16:49:01 Z bachhoangxuan Longest Trip (IOI23_longesttrip) C++17
5 / 100
8 ms 496 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn=305;
vector<int> cc[maxn];

vector<int> longest_trip(int N, int D)
{
    for(int i=0;i<N;i++) cc[i].clear();
    vector<int> res={0};
    set<int> s;
    for(int i=1;i<N;i++){
        cc[i].push_back(i);
        s.insert(i);
    }
    while(!s.empty()){
        int st=-1;
        bool check=false;
        for(int x:s){
            s.erase(x);
            if(!are_connected({res.back()},cc[x])){
                if(st==-1) st=x;
                else for(int u:cc[x]) cc[st].push_back(u);
            }
            else{
                check=true;
                int l=1,r=(int)cc[x].size();
                while(l<r){
                    int mid=(l+r)>>1;
                    vector<int> v(cc[x].begin(),cc[x].begin()+mid);
                    if(are_connected({res.back()},v)) r=mid;
                    else l=mid+1;
                }
                r--;
                res.push_back(cc[x][r]);
                for(int u:cc[x]) if(u!=cc[x][r]) res.push_back(u);
                break;
            }
        }
        if(!check){
            int l=1,r=(int)cc[st].size(),p=-1;
            while(l<r){
                int mid=(l+r)>>1;
                vector<int> v(cc[st].begin(),cc[st].begin()+mid);
                if(are_connected(res,v)) p=cc[st][mid-1],r=mid;
                else l=mid+1;
            }
            if(p==-1){
                if((int)cc[st].size()>(int)res.size()) swap(res,cc[st]);
            }
            else{
                reverse(res.begin(),res.end());
                if(!are_connected({res.back()},{p})){
                    l=1,r=(int)res.size();
                    while(l<r){
                        int mid=(l+r)>>1;
                        vector<int> v(res.begin(),res.begin()+mid);
                        if(are_connected({p},v)) r=mid;
                        else l=mid+1;
                    }
                    res.insert(res.end(),res.begin(),res.begin()+r);
                    res.erase(res.begin(),res.begin()+r);

                }
                res.push_back(p);
                for(int u:cc[st]) if(u!=p) res.push_back(u);
            }
        }
        else if(st!=-1) s.insert(st);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Runtime error 1 ms 344 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 7 ms 496 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Runtime error 1 ms 344 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Runtime error 1 ms 344 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -