Submission #1067610

# Submission time Handle Problem Language Result Execution time Memory
1067610 2024-08-20T21:27:37 Z golf Longest Trip (IOI23_longesttrip) C++17
5 / 100
10 ms 600 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

int pop(queue<int> &q) {
    int x = q.front();
    q.pop();
    return x;
}

const bool maybe = true;

vector<int> longest_trip(int N, int D) {
    queue<int> nodes;
    for (int i = 0; i < N; i++) nodes.push(i);

    vector<int> a, b;
    a.push_back(pop(nodes));

    bool ends_connected = maybe;
    // false = a and b are not connected
    // true  = a and b are maybe connected
    while (!nodes.empty()) {
        if (b.empty()) {
            int n = pop(nodes);
            if (are_connected({a.back()}, {n})) {
                a.push_back(n);
            } else {
                // missed optimization
                // we could cache that a and b are not connected
                b.push_back(n);
                ends_connected = false;
            }
            continue;
        }

        // both a and b are non-empty
        int n = pop(nodes);

        if (are_connected({a.back()}, {n})) {
            a.push_back(n);
            ends_connected = maybe;
        } else if (are_connected({b.back()}, {n})) {
            b.push_back(n);
            ends_connected = false;
        } else {
            // ends of a and b are definitely connected
            for (int i = 0; i < b.size(); i++) {
                a.push_back(b.back());
                b.pop_back();
            }

            assert(b.empty());
            b.push_back(n);
        }
    }

    if (b.empty()) {
        return a;
    }

    if (ends_connected == maybe && are_connected({a.back()}, {b.back()})) {
        for (int i = 0; i < b.size(); i++) {
            a.push_back(b.back());
            b.pop_back();
        }

        return a;
    }

    if (!are_connected(a, b)) {
        if (a.size() > b.size()) {
            return a;
        } else {
            return b;
        }
    }

    // not finished
    if (a.size() > b.size()) {
        return a;
    } else {
        return b;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:48:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for (int i = 0; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
longesttrip.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int i = 0; i < b.size(); i++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 0 ms 600 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 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 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 404 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 424 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 10 ms 596 KB Output is correct
15 Runtime error 6 ms 344 KB Execution killed with signal 6
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 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 4 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -