Submission #1081718

# Submission time Handle Problem Language Result Execution time Memory
1081718 2024-08-30T09:33:37 Z slivajan Longest Trip (IOI23_longesttrip) C++17
15 / 100
8 ms 344 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

typedef int un;
typedef vector<un> vuc;
typedef deque<un> duc;

#define REP(i, a, b) for (un i = (un)a; i < (un)b; i++)
#define FEAC(i, a) for (auto&& i : a)
#define ALL(x) (x).begin(), (x).end()
#define vec vector
#define DEB(x) cerr << #x << " = " << x << endl;

un bs(un from, vuc field){
    un L = 0;
    un R = field.size();

    while (R-L > 1)
    {
        un M = (L+R)/2;

        if (are_connected({from}, vuc(field.begin() + L, field.begin()+M))){
            R = M;
        }
        else{
            L = M;
        }
    }

    return field[L];
    
}

std::vector<int> longest_trip(int N, int D)
{
    if (D == 3){
        vuc ret(N);
        iota(ALL(ret), 0);
        return ret;
    }

    if (D == 2){
        duc ret;
        
        if (not are_connected({0}, {1})){
            ret = {0, 2, 1};
        }
        else if (not are_connected({1}, {2})){
            ret = {1, 0, 2};
        }
        else {
            ret = {0, 1, 2};
        }

        REP(i, 3, N){
            if (are_connected({ret.back()}, {i})){
                ret.push_back(i);
            }
            else{
                ret.push_front(i);
            }
        }

        return vuc(ALL(ret));
    }

    if (D == 1){
        vuc ret = {0};
        vec<bool> was_used(N, false);
        was_used[0] = true;

        while (true)
        {
            vuc not_used = {};
            REP(i, 0, N){
                if (not was_used[i]){
                    not_used.push_back(i);
                }

                if (not are_connected(not_used, {ret[ret.size()-1]})){
                    if (ret.size() > not_used.size()){
                        return ret;
                    }
                    else{
                        return not_used;
                    }
                }

                ret.push_back(bs(ret[ret.size()-1], not_used));
            }
        }
        
        return ret;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:97:1: warning: control reaches end of non-void function [-Wreturn-type]
   97 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 8 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 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 8 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -