Submission #1007135

# Submission time Handle Problem Language Result Execution time Memory
1007135 2024-06-24T12:11:35 Z De3b0o Longest Trip (IOI23_longesttrip) C++17
0 / 100
45 ms 1112 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
#include<random>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)

using namespace std;

ll v[300][300];
vector<ll> adj[300];
ll mx;
vector<int> trnbo;

void lt(ll x , set<ll> s , vector<int> t)
{
    ll e = 0;
    for(auto it : adj[x])
    {
        if(s.find(it)!=s.end())
            continue;
        e++;
        set<ll> ss = s;
        vector<int> tt = t;
        tt.pb(it);
        ss.in(it);
        lt(it,ss,tt);
    }
    if(e==0)
    {
        if(t.size()>mx)
        {
            mx=t.size();
            trnbo=t;
        }
    }
}

std::vector<int> longest_trip(int N, int D)
{
    memset(v,-1,sizeof(v));
    ll n = N;
    ll e = 32640;
    vector<ll> idx;
    for(int i = 0 ; n>i ; i++)
        idx.pb(i);
    random_device rd;
    mt19937 g(rd());
    shuffle(idx.begin(),idx.end(),g);
    for(int i = 0 ; n>i ; i++)
    {
        for(int j = i+1 ; n>j ; j++)
        {
            if(e==0)
                break;
            if(v[idx[i]][idx[j]]!=-1)
                continue;
            e--;
            v[idx[i]][idx[j]]=are_connected({idx[i]},{idx[j]});
            v[idx[j]][idx[i]]=v[idx[i]][idx[j]];
        }
        vector<ll> z;
        for(int j = 0 ; n>j ; j++)
        {
            if(idx[i]==idx[j])
                continue;
            if(v[idx[i]][j]==0)
                z.pb(j);
        }
        if(z.size()>1)
        {
            for(int i1 = 0 ; z.size()>i1 ; i1++)
            {
                for(int i2 = 0 ; z.size()>i2 ; i2++)
                {
                    if(i1==i2)
                        continue;
                    v[i1][i2]=1;
                    v[i2][i1]=1;
                }
            }
        }
    }
    for(int i = 0 ; n>i ; i++)
    {
        for(int j = 0 ; n>i ; i++)
        {
            if(v[i][j]==1)
                adj[i].pb(j);
        }
    }
    for(int i = 0 ; n>i ; i++)
        lt(i,{i},{i});
    return trnbo;
}

Compilation message

longesttrip.cpp: In function 'void lt(long long int, std::set<long long int>, std::vector<int>)':
longesttrip.cpp:45:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |         if(t.size()>mx)
      |            ~~~~~~~~^~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:73:62: warning: narrowing conversion of 'idx.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   73 |             v[idx[i]][idx[j]]=are_connected({idx[i]},{idx[j]});
      |                                                              ^
longesttrip.cpp:73:62: warning: narrowing conversion of 'idx.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:73:62: warning: narrowing conversion of 'idx.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)j))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:73:62: warning: narrowing conversion of 'idx.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)j))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:86:38: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |             for(int i1 = 0 ; z.size()>i1 ; i1++)
      |                              ~~~~~~~~^~~
longesttrip.cpp:88:42: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |                 for(int i2 = 0 ; z.size()>i2 ; i2++)
      |                                  ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1112 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1112 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1112 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1112 KB Incorrect
2 Halted 0 ms 0 KB -