제출 #767290

#제출 시각아이디문제언어결과실행 시간메모리
767290t6twotwo수천개의 섬 (IOI22_islands)C++17
55 / 100
33 ms6108 KiB
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
    if (N == 2) {
        vector<int> a, b;
        for (int i = 0; i < M; i++) {
            if (U[i] == 0) {
                a.push_back(i);
            } else {
                b.push_back(i);
            }
        }
        if (a.size() >= 2 && b.size() >= 1) {
            return vector{a[0], b[0], a[1], a[0], b[0], a[1]};
        } else {
            return false;
        }
    }
    bool subtask3 = 0;
    bool subtask4 = 0;
    if (M % 2 == 0) {
        subtask3 = 1;
        subtask4 = 1;
        for (int i = 0; i < M; i += 2) {
            if (U[i] != V[i + 1] || V[i] != U[i + 1]) {
                subtask3 = 0;
            }
            if (U[i] != U[i + 1] || V[i] != V[i + 1]) {
                subtask4 = 0;
            }
        }
    }
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < M; i++) {
        adj[U[i]].emplace_back(V[i], i);
    }
    if (subtask3) {
        vector<int> ans;
        int x = 0, p = -1;
        while (1) {
            vector<array<int, 2>> f;
            for (auto [y, z] : adj[x]) {
                if (y != p) {
                    f.push_back({y, z});
                }
            }
            if (f.empty()) {
                return false;
            }
            if (f.size() == 1) {
                ans.push_back(f[0][1]);
                p = x;
                x = f[0][0];
                continue;
            }
            auto v = vector(ans.rbegin(), ans.rend());
            vector<int> s(M);
            ans.push_back(f[0][1]);
            ans.push_back(f[0][1] ^ 1);
            ans.push_back(f[1][1]);
            ans.push_back(f[1][1] ^ 1);
            ans.push_back(f[0][1] ^ 1);
            ans.push_back(f[0][1]);
            ans.push_back(f[1][1] ^ 1);
            ans.push_back(f[1][1]);
            ans.insert(ans.end(), v.begin(), v.end());
            return ans;
        }
    }
    if (subtask4) {
        vector<int> p, ans, vis(N);
        auto dfs = [&](auto dfs, int x) -> bool {
            vis[x] = 1;
            for (auto [y, z] : adj[x]) {
                if (vis[y] == 1) {
                    p.push_back(z);
                    int t = 0, q = 0;
                    while (t != y) {
                        t ^= U[p[q]] ^ V[p[q]];
                        q++;
                    }
                    for (int i = 0; i < q; i++) {
                        ans.push_back(p[i]);
                    }
                    for (int i = q; i < p.size(); i++) {
                        ans.push_back(p[i]);
                    }
                    for (int i = q; i < p.size(); i++) {
                        ans.push_back(p[i] ^ 1);
                    }
                    for (int i = p.size() - 1; i >= q; i--) {
                        ans.push_back(p[i]);
                    }
                    for (int i = p.size() - 1; i >= q; i--) {
                        ans.push_back(p[i] ^ 1);
                    }
                    for (int i = q - 1; i >= 0; i--) {
                        ans.push_back(p[i]);
                    }
                    return 1;
                }
                if (!vis[y]) {
                    p.push_back(z);
                    if (dfs(dfs, y)) {
                        return 1;
                    }
                    p.pop_back();
                }
            }
            vis[x] = 2;
            return 0;
        };
        if (dfs(dfs, 0)) {
            return ans;
        } else {
            return false;
        }
    }
    int s[3][3];
    for (int i = 0; i < M; i++) {
        if (U[i] < 3 && V[i] < 3) {
            s[U[i]][V[i]] = i;
        }
    }
    return vector{s[0][1], s[1][2], s[2][0], s[0][2], s[2][1], s[1][0], s[2][0], s[1][2], s[0][1], s[1][0], s[2][1], s[0][2]};
}

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In instantiation of 'find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)> [with auto:23 = find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)>]':
islands.cpp:114:23:   required from here
islands.cpp:86:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                     for (int i = q; i < p.size(); i++) {
      |                                     ~~^~~~~~~~~~
islands.cpp:89:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                     for (int i = q; i < p.size(); i++) {
      |                                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...