QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201885#5160. Kebab PizzaS_Explosion#WA 1ms9160kbC++202.9kb2023-10-05 17:21:332023-10-05 17:21:33

Judging History

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

  • [2023-10-05 17:21:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9160kb
  • [2023-10-05 17:21:33]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
#include <bitset>

template <typename Tp>
inline void read(Tp &x) {
    x = 0;
    bool f = true; char ch = getchar();
    for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
    for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
    x = f ? x : -x;
}

const int N = 1e5;

bool vis[N + 5];
int cnt, c1[N + 5], c2[N + 5];
std::vector<int> col[N + 5], Vec[N + 5];

int solve(int c) {
    int cnt = 0, c1 = 0, c2 = 0, res = 0;
    for (int Col : col[c]) {
        if ((int)col[Col].size() > 1) {
            ++cnt;
            if (c1) c2 = Col;
            else c1 = Col;
        }
    }
    if (cnt > 2) return -1;
    for (int x : Vec[c]) vis[x] = true, ++res;
    if (!cnt) return 0;

    int lst = c, cc = 0;
    while (1) {
        cnt = cc = 0;
        for (int Col : col[c1]) {
            if (Col != lst && (int)col[Col].size() > 1) {
                ++cnt;
                cc = Col;
            }
        }
        if (cnt > 1) return -1;
        for (int x : Vec[c1])
            if (!vis[x]) vis[x] = true, ++res;
        if (cnt == 0) break;
        lst = c1, c1 = cc;
        if (cc == c2) {
            for (int Col : col[c2]) {
                if (Col != lst && Col != c && (int)col[Col].size() > 1) return -1;
            }
            for (int x : Vec[c2])
                if (!vis[x]) vis[x] = true, ++res;
            return res;
        }
    }

    if (c2) {
        lst = c, cc = 0;
        while (1) {
            cnt = cc = 0;
            for (int Col : col[c2]) {
                if (Col != lst && (int)col[Col].size() > 1) {
                    ++cnt;
                    cc = Col;
                }
            }
            if (cnt > 1) return -1;
            for (int x : Vec[c1])
                if (!vis[x]) vis[x] = true, ++res;
            if (cnt == 0) break;
            lst = c2, c2 = cc;
        }
    }

    return 0;
}

int main() {
    int n, k;
    read(n), read(k);
    for (int i = 1; i <= n; ++i) {
        int a, b;
        read(a), read(b);
        c1[i] = a, c2[i] = b;
        if (a == b) {
            Vec[a].push_back(i);
        }
        else {
            col[a].push_back(b), col[b].push_back(a);
            Vec[a].push_back(i), Vec[b].push_back(i);
        }
    }
    for (int i = 1; i <= k; ++i) {
        std::sort(col[i].begin(), col[i].end());
        std::vector<int> v = col[i];
        col[i].clear();
        for (int j = 0; j < (int)v.size(); ++j) {
            if (!j || v[j] != v[j - 1]) col[i].push_back(v[j]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (vis[i]) continue;
        int res = solve(c1[i]);
        if (res == -1 || (res > 0 && res < n)) return puts("impossible"), 0;
    }

    puts("possible");
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 8504kb

input:

7 6
2 2
3 6
1 1
1 5
4 5
6 6
6 5

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 1ms
memory: 8500kb

input:

5 5
1 3
1 5
2 3
2 5
3 4

output:

possible

result:

ok single line: 'possible'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8336kb

input:

6 7
1 2
2 3
3 4
4 5
3 6
6 7

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 1ms
memory: 9016kb

input:

8 4
1 1
1 2
2 1
2 2
3 3
3 4
4 3
4 4

output:

possible

result:

ok single line: 'possible'

Test #5:

score: 0
Accepted
time: 1ms
memory: 8296kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 8544kb

input:

5 4
1 1
1 4
2 2
2 4
3 4

output:

possible

result:

ok single line: 'possible'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 9160kb

input:

6 4
1 1
1 4
2 2
2 4
3 3
3 4

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'