Submission #1002328

# Submission time Handle Problem Language Result Execution time Memory
1002328 2024-06-19T12:34:20 Z Wael Longest Trip (IOI23_longesttrip) C++17
0 / 100
1 ms 344 KB
#include "longesttrip.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

vector<int> operator+=(vector<int> &a, vector<int> b) {
    for (auto j : b) {
        a.push_back(j);
    }
    return a;
}

vector<int> longest_trip(int N, int D) {
    int n = N;
    vector<int> a, b, c;

    auto ask = [&](int x, int y) -> bool {
        return are_connected(vector<int>{x}, vector<int>{y});
    };

    for (int i = 1; i < n; ++i) {
        b.push_back(i);
    }
    a.push_back(0);
    while (true) {
        for (auto j : a) {
            cout << j << " ";
        }
        cout << "\n";
        for (auto j : b) {
            cout << j << " ";
        }
        cout << "\n";
        for (auto j : c) {
            cout << j << " ";
        }
        cout << "\n";

        vector<int> last{a.back()};
        if (c.size() && are_connected(last, c)) {
            int l = 1, r = c.size();
            while (l <= r) {
                int mid = (l + r) / 2;
                if (are_connected(last, vector<int>(c.begin(), c.begin() + mid))) {
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
            }
            ++r;
            a.emplace_back(c[r - 1]);
            a += vector<int>(c.begin(), c.begin() + r - 1);
            a += vector<int>(c.begin() + r, c.end());
            c.clear();
            continue;
        }
        while (b.size() && are_connected(last, vector<int>{b.back()}) == 0) {
            c.push_back(b.back());
            b.pop_back();
        }
        if (b.size()) {
            a.push_back(b.back());
            b.pop_back();
        } else {
            if (are_connected(a, c) == 0) {
                if (a.size() < c.size()) {
                    swap(a, c);
                }
            } else {
                if (c.size()) {
                    int l = 1, r = c.size();
                    while (l <= r) {
                        int mid = (l + r) / 2;
                        if (are_connected(a, vector<int>(c.begin(), c.begin() + mid))) {
                            r = mid - 1;
                        } else {
                            l = mid + 1;
                        }
                    }
                    ++r;
                    int x = c[r - 1];
                    while (ask(a[0], x) == 0 && ask(a.back(), x) == 0) {
                        a.push_back(a[0]);
                        a.erase(a.begin());
                    }
                    if (ask(a[0], x)) {
                        reverse(a.begin(), a.end());
                    }
                    a.emplace_back(x);
                    a += vector<int>(c.begin(), c.begin() + r - 1);
                    a += vector<int>(c.begin() + r, c.end());
                    c.clear();
                }
            }
            break;
        }
    }

    return a;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Secret mismatch (possible tampering with the output).
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Secret mismatch (possible tampering with the output).
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Secret mismatch (possible tampering with the output).
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Secret mismatch (possible tampering with the output).
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Secret mismatch (possible tampering with the output).
2 Halted 0 ms 0 KB -