Submission #899580

# Submission time Handle Problem Language Result Execution time Memory
899580 2024-01-06T13:39:58 Z Szil Longest Trip (IOI23_longesttrip) C++17
0 / 100
9 ms 596 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);
    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:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 1; i < ans.size(); i++) {
      |                         ~~^~~~~~~~~~~~
longesttrip.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
longesttrip.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     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:50:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     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 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 8 ms 344 KB Output is correct
6 Runtime error 1 ms 596 KB Execution killed with signal 6
7 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 -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -