QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84929#4513. Slide Paradewangzhe_04770 15080ms32380kbC++232.4kb2023-03-06 21:04:522023-03-06 21:04:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 21:04:53]
  • 评测
  • 测评结果:0
  • 用时:15080ms
  • 内存:32380kb
  • [2023-03-06 21:04:52]
  • 提交

answer

// Google Code Jam 2022 World Finals
// Problem C. Slide Parade
#include <bits/stdc++.h>

using LL = long long;
using ULL = unsigned LL;

constexpr ULL E(long double x, int y) {
    while (y--) x *= 10;
    return x;
}
constexpr ULL SIZE(long double x, int y) {return E(x, y) + 5;}

const int inf32 = E(1, 9) + 5;
const LL inf64 = E(1, 18) + 5;

bool vis[205];
int n, m, mat[205], a[205][205];
std::pair<int, int> edge[5005];
std::vector<int> graph[205];
std::vector<int> ans;

bool Hungarian(int u) {
    if (vis[u]) return false;
    vis[u] = true;
    for (int v : graph[u]) {
        if (mat[v] && !Hungarian(mat[v])) continue;
        mat[v] = u;
        return true;
    }
    return false;
}
bool Dfs(int u, int s) {
    if (vis[u]) return false;
    vis[u] = true;
    if (mat[u] == s) return true;
    int w = mat[u];
    for (int v : graph[w]) {
        if (!Dfs(v, s)) continue;
        mat[v] = w;
        mat[u] = s;
        return true;
    }
    return false;
}

void Euler(int u) {
    for (int v = 1; v <= n; v++) {
        if (!a[u][v]) continue;
        a[u][v]--;
        Euler(v);
        ans.push_back(u);
    }
}

void Solve(int data) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        mat[i] = 0;
        graph[i].clear();
        for (int j = 1; j <= n; j++) a[i][j] = 0;
    }
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[i] = {x, y};
        graph[x].push_back(y);
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) vis[j] = false;
        cnt += Hungarian(i);
    }
    if (cnt < n) {
        printf("Case #%d: IMPOSSIBLE\n", data);
        return;
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) vis[j] = false;
        if (!Dfs(edge[i].second, edge[i].first)) {
            printf("Case #%d: IMPOSSIBLE\n", data);
            return;
        }
        for (int j = 1; j <= n; j++) a[mat[j]][j]++;
    }
    ans.clear();
    ans.push_back(1);
    Euler(1);
    std::reverse(ans.begin(), ans.end());
    printf("Case #%d: %llu\n", data, ans.size());
    for (int x : ans) printf("%d ", x);
    putchar('\n');
}

int main() {
    int data_count;
    scanf("%d", &data_count);
    for (int data = 1; data <= data_count; data++) Solve(data);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3508kb

input:

100
5 8
1 2
1 3
1 4
1 5
2 1
3 1
4 1
5 1
5 10
1 3
1 4
2 3
2 5
3 1
3 4
3 5
4 2
5 1
5 3
5 10
1 4
2 3
2 5
3 1
3 5
4 2
4 3
4 5
5 1
5 2
3 6
1 2
1 3
2 1
2 3
3 1
3 2
5 10
1 2
1 5
2 3
2 4
3 1
4 3
4 5
5 2
5 3
5 4
4 10
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 4
4 2
4 3
5 10
1 2
1 3
2 1
2 4
3 1
3 5
4 2
4 5
5 3
5 4
5 10
1 ...

output:

Case #1: IMPOSSIBLE
Case #2: 51
1 3 1 3 1 4 2 3 1 4 2 3 1 4 2 3 4 2 3 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 3 5 3 5 3 5 3 5 1 
Case #3: 51
1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 3 5 1 4 3 5 1 4 3 5 1 4 3 5 1 4 5 2 3 5 2 5 2 5 2 5 2 5 1 
Case #4: 19
1 2 1 2 1 2 1 3 1 3 1 3 2 3 2 3 2 3 1 ...

result:

wrong answer the slide from 3 to 4 hasn't be used (test case 25)

Test #2:

score: 0
Wrong Answer
time: 15080ms
memory: 32380kb

input:

100
199 4980
1 95
1 96
1 105
1 124
1 130
1 131
1 135
1 137
1 139
1 140
1 141
1 147
1 155
1 172
1 174
1 179
1 183
1 188
1 193
1 196
1 197
2 3
2 5
2 13
2 14
2 17
2 20
2 24
2 26
2 30
2 41
2 44
2 45
2 52
2 56
2 67
2 70
2 71
2 74
2 78
2 84
2 85
2 90
2 92
2 93
2 97
2 107
2 111
2 113
2 122
2 124
2 128
2 13...

output:

Case #1: IMPOSSIBLE
Case #2: IMPOSSIBLE
Case #3: 1000001
1 18 13 9 5 3 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 1...

result:

wrong answer the slide from 3 to 4 hasn't be used (test case 27)