답안 #939417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939417 2024-03-06T10:48:56 Z WanWan 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
1000 ms 848 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 260;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi; 

vector<int>out;
int n,d;
bool mat[MAXN][MAXN];
bool vis[MAXN];

void dfs(int x){
    vis[x]=1;
    out.push_back(x);
    vector<int> ord;
    for(int i=0;i<n;i++){
        ord.push_back(i);
    }
    shuffle(ord.begin(),ord.end(),rng);
    for(auto i:ord){
        if(mat[x][i] && !vis[i]){
            dfs(i);
            return;
        }
    }
}
vector<int>solve(int st){
    memset(vis,0,sizeof vis);
    out.clear();
    dfs(st);
    return out;
}
std::vector<int> longest_trip(int N, int D)
{
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mat[i][j]=0;
        }
    }
    
    n=N;
    d=D;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            vector<int>A;A.push_back(i);
            vector<int>B;B.push_back(j);
            mat[i][j]=mat[j][i]=are_connected(A,B);
        }
    }
    if(n<=9){
        vector<int> vec;
        vector<int> ans;
        for(int i=0;i<n;i++)vec.push_back(i);
        do {
            int cur=vec[0];
            vector<int>hh;
            hh.push_back(cur);
            for(int i=1;i<vec.size();i++){
                if(mat[cur][vec[i]]){
                    hh.push_back(vec[i]);
                    cur=vec[i];
                }
            }
            if(hh.size()>ans.size())ans=hh;
        } while(next_permutation(vec.begin(),vec.end()));
        return ans;
    }
    vector<int> ans;
    for(int i=0;i<n;i++){//starting point
        vector<int>res=solve(i);
        if(res.size()>ans.size())ans=res;
    }
    return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int i=1;i<vec.size();i++){
      |                         ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 405 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 170 ms 600 KB Output is correct
4 Correct 603 ms 456 KB Output is correct
5 Execution timed out 1728 ms 740 KB Time limit exceeded
6 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 157 ms 600 KB Output is correct
4 Correct 602 ms 848 KB Output is correct
5 Execution timed out 1734 ms 736 KB Time limit exceeded
6 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 175 ms 600 KB Output is correct
4 Correct 628 ms 452 KB Output is correct
5 Execution timed out 1686 ms 740 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 160 ms 600 KB Output is partially correct
4 Partially correct 644 ms 452 KB Output is partially correct
5 Execution timed out 1703 ms 744 KB Time limit exceeded
6 Halted 0 ms 0 KB -