Submission #1081729

# Submission time Handle Problem Language Result Execution time Memory
1081729 2024-08-30T09:38:57 Z slivajan Longest Trip (IOI23_longesttrip) C++17
40 / 100
68 ms 952 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_used.size() == 0) break;

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

            un now = bs(ret[ret.size()-1], not_used);
            ret.push_back(now);
            was_used[now] = true;
        }
        
        return ret;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:101:1: warning: control reaches end of non-void function [-Wreturn-type]
  101 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 17 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 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 7 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 7 ms 344 KB Output is correct
10 Correct 7 ms 436 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 14 ms 344 KB Output is correct
3 Correct 32 ms 344 KB Output is correct
4 Correct 50 ms 344 KB Output is correct
5 Correct 66 ms 952 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 32 ms 344 KB Output is correct
9 Correct 41 ms 344 KB Output is correct
10 Correct 54 ms 344 KB Output is correct
11 Correct 51 ms 600 KB Output is correct
12 Correct 51 ms 344 KB Output is correct
13 Correct 60 ms 600 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 18 ms 344 KB Output is correct
17 Correct 21 ms 344 KB Output is correct
18 Correct 28 ms 344 KB Output is correct
19 Correct 42 ms 444 KB Output is correct
20 Correct 42 ms 344 KB Output is correct
21 Correct 53 ms 344 KB Output is correct
22 Correct 51 ms 344 KB Output is correct
23 Correct 64 ms 452 KB Output is correct
24 Correct 60 ms 344 KB Output is correct
25 Correct 7 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 20 ms 340 KB Output is correct
28 Correct 12 ms 344 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 28 ms 344 KB Output is correct
31 Correct 19 ms 344 KB Output is correct
32 Correct 19 ms 344 KB Output is correct
33 Correct 36 ms 344 KB Output is correct
34 Correct 33 ms 344 KB Output is correct
35 Correct 38 ms 344 KB Output is correct
36 Correct 58 ms 344 KB Output is correct
37 Correct 52 ms 596 KB Output is correct
38 Correct 52 ms 344 KB Output is correct
39 Correct 42 ms 344 KB Output is correct
40 Correct 49 ms 708 KB Output is correct
41 Correct 28 ms 444 KB Output is correct
42 Correct 44 ms 344 KB Output is correct
43 Correct 50 ms 344 KB Output is correct
44 Correct 34 ms 460 KB Output is correct
45 Correct 10 ms 344 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 12 ms 344 KB Output is correct
48 Correct 13 ms 344 KB Output is correct
49 Correct 10 ms 344 KB Output is correct
50 Correct 25 ms 344 KB Output is correct
51 Correct 30 ms 344 KB Output is correct
52 Correct 23 ms 512 KB Output is correct
53 Correct 27 ms 344 KB Output is correct
54 Correct 26 ms 344 KB Output is correct
55 Correct 31 ms 344 KB Output is correct
56 Correct 53 ms 468 KB Output is correct
57 Correct 63 ms 856 KB Output is correct
58 Correct 39 ms 600 KB Output is correct
59 Correct 47 ms 720 KB Output is correct
60 Correct 42 ms 344 KB Output is correct
61 Correct 50 ms 344 KB Output is correct
62 Correct 55 ms 344 KB Output is correct
63 Correct 35 ms 344 KB Output is correct
64 Correct 39 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 21 ms 344 KB Output is correct
4 Partially correct 44 ms 600 KB Output is partially correct
5 Partially correct 68 ms 708 KB Output is partially correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -