답안 #1004830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004830 2024-06-21T17:33:18 Z Wael 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
9 ms 600 KB
#include "longesttrip.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

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

    vector<int> a{0}, b;
    for (int i = 1; i < n; ++i) {
        if (ask(a.back(), i)) {
            a.push_back(i);
        } else {
            b.push_back(i);
        }
        if (b.size() && ask(b.back(), a.back())) {
            reverse(b.begin(), b.end());
            for (auto j : b) {
                a.push_back(j);
            }
            b.clear();
        }
    }

    if (b.size() && are_connected(a, b)) {
        if (are_connected(vector<int>{a.back()}, vector<int>(b.begin(), b.end())) == 0) {
            int l = 1, r = b.size();
            while (l <= r) {
                int mid = (l + r) / 2;
                if (are_connected(a, vector<int>(b.begin(), b.begin() + mid))) {
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
            }
            ++r;
            swap(b[r - 1], b.back());
            swap(a, b);
        }
        if (ask(a.back(), b.back())) {
            reverse(b.begin(), b.end());
        }
        int l = 1, r = b.size();
        while (l <= r) {
            int mid = (l + r) / 2;
            if (are_connected(vector<int>{a.back()}, vector<int>(b.begin(), b.begin() + mid))) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        --l;
        while (l--) {
            b.push_back(b.back());
            b.erase(b.begin());
        }
        for (auto j : b) {
            a.push_back(j);
        }
        b.clear();
    } else {
        if (a.size() < b.size()) {
            swap(a, b);
        }
    }

    return a;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 4 ms 344 KB Output is correct
5 Correct 6 ms 436 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 8 ms 344 KB Output is correct
16 Incorrect 0 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 5 ms 344 KB Output is correct
5 Correct 7 ms 436 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 9 ms 356 KB Output is correct
16 Incorrect 0 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -