Submission #899583

# Submission time Handle Problem Language Result Execution time Memory
899583 2024-01-06T13:43:56 Z Szil Longest Trip (IOI23_longesttrip) C++17
0 / 100
9 ms 600 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

// bool are_connected(int[] A, int[] B);

vector<int> longest_trip(int N, int D)
{
    assert(D == 2);

    if (N == 3) {

        if (are_connected({0}, {1}) && are_connected({1}, {2})) return {0, 1, 2};
        return {0, 2, 1};
    }

    queue<int> q;
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        q.push(i);
    }
    int extra = -1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        ans.emplace_back(u);
        if (q.empty()) continue;

        int v = q.front();
        if (!are_connected({u}, {v})) {
            q.pop();
            if (q.empty()) {
                extra = v;
            } else {
                q.push(v);
            }
        }
    }
    int insert = -1;
    if (extra != -1) {
        for (int i = 1; i < ans.size(); i++) {
            if (are_connected({ans[i-1]}, {extra}) && are_connected({extra}, {ans[i]})) {
                insert = i;
                break;
            }
        }
    }
    vector<int> res;
    for (int i = 0; i < ans.size(); i++) {
        if (i == insert) res.emplace_back(extra);
        res.emplace_back(ans[i]);
    }
    for (int i = 1; i < res.size(); i++) {
        assert(are_connected({res[i-1]}, {res[i]}));
    }
    assert(res.size() == N);
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 1; i < ans.size(); i++) {
      |                         ~~^~~~~~~~~~~~
longesttrip.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
longesttrip.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 1; i < res.size(); i++) {
      |                     ~~^~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:1:
longesttrip.cpp:57:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |     assert(res.size() == N);
      |            ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 424 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 9 ms 600 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -