QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422363#5956. Paradox Sorthelhy0 269ms3868kbC++143.3kb2024-05-27 12:38:282024-05-27 12:38:29

Judging History

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

  • [2024-05-27 12:38:29]
  • 评测
  • 测评结果:0
  • 用时:269ms
  • 内存:3868kb
  • [2024-05-27 12:38:28]
  • 提交

answer

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

using namespace std;
const int N = 105;

int n, A;

bitset<N> out[N], in[N], vis;

void bfs(int S, bitset<N> g[N])
{
    queue<int> q;
    q.push(S);
    vis[S] = true;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = 0; i < n; i++)
        {
            if (g[u][i] && !vis[i])
            {
                vis[i] = true;
                q.push(i);
            }
        }
    }
}

int ans[N];
bool solve()
{
    bitset<N> now, tmp;
    int last = -1;
    for (int i = 0; i < n; i++)
    {
        bool suc = false;
        for (int u = 0; u < n; u++)
        {
            if (now[u]) continue;

            if (~last && !out[last][u])
            {
                if (u == A) continue;
                now[u] = true;

                vis = now;
                bfs(last, out);
                tmp = vis;

                vis = now;
                bfs(A, in);
                tmp = (tmp & vis) & ~now;

                bool flag = true;
                for (int v = 0; v < n; v++)
                {
                    if (tmp[v] || now[v]) continue;
                    if ((out[v] & tmp).none())
                    {
                        now[u] = flag = false;
                        break;
                    }
                }

                if (flag)
                {
                    ans[i] = u;
                    suc = true;
                    break;
                }
            }
            else
            {
                vis = now;
                vis[u] = true;
                bfs(u, out);
                tmp = vis;

                vis = now;
                vis[u] = true;
                bfs(A, in);
                tmp = (tmp & vis) & ~now;

                bool flag = true;
                for (int v = 0; v < n; v++)
                {
                    if (tmp[v] || now[v]) continue;
                    if ((out[v] & tmp).none())
                    {
                        flag = false;
                        break;
                    }
                }

                if (flag)
                {
                    now[u] = suc = true;
                    ans[i] = last = u;
                    break;
                }
            }
        }
        if (!suc)
            return false;
    }
    return true;
}

int main()
{
    int T;
    cin >> T;
    for (int t = 1; t <= T; t++)
    {
        cin >> n >> A;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                char c;
                scanf(" %c", &c);
                in[i][j] = (c == 'Y');
                out[i][j] = (c == 'N');
            }
        }
        for (int i = 0; i < n; i++)
        {
            out[A][i] = false;
        }
        printf("Case #%d:", t);
        if (!solve())
        {
            printf(" IMPOSSIBLE\n");
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                printf(" %d", ans[i]);
            }
            putchar('\n');
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3868kb

input:

100
3 0
-YN
N-Y
YN-
2 0
-Y
N-
5 0
-YNNN
N-YNN
YN-YN
YYN-Y
YYYN-
5 1
-NYYY
Y-NNN
NY-NY
NYY-N
NYNY-
6 5
-YYNNY
N-YYNY
NN-NYN
YNY-NY
YYNY-Y
NNYNN-
4 0
-YYY
N-YN
NN-N
NYY-
2 0
-Y
N-
5 1
-NYNY
Y-YYY
NN-YY
YNN-N
NNNY-
7 5
-YYYYYY
N-NNYYN
NY-YNNN
NYN-NYN
NNYY-NN
NNYNY-N
NYYYYY-
8 0
-YNNNNNN
N-YNNNNN
YN-YNN...

output:

Case #1: 1 2 0
Case #2: 0 1
Case #3: 3 4 2 1 0
Case #4: IMPOSSIBLE
Case #5: 0 1 3 4 2 5
Case #6: IMPOSSIBLE
Case #7: 0 1
Case #8: IMPOSSIBLE
Case #9: IMPOSSIBLE
Case #10: 6 7 5 4 3 2 1 0
Case #11: IMPOSSIBLE
Case #12: 0 1
Case #13: 0 1
Case #14: IMPOSSIBLE
Case #15: IMPOSSIBLE
Case #16: 7 8 6 5 4 3 ...

result:

wrong answer 4th lines differ - expected: 'Case #4: 0 2 3 4 1', found: 'Case #4: IMPOSSIBLE'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 269ms
memory: 3728kb

input:

100
39 0
-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
N-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYYN-YNN...

output:

Case #1: 37 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Case #2: IMPOSSIBLE
Case #3: IMPOSSIBLE
Case #4: 4 12 6 9 8 7 10 5 11 3 2 1 0
Case #5: IMPOSSIBLE
Case #6: IMPOSSIBLE
Case #7: IMPOSSIBLE
Case #8: IMPOSSIBLE
Case #9: IMPOSSIBLE
Case #...

result:

wrong answer 2nd lines differ - expected: 'Case #2: 0 13 23 28 30 34 38 4...45 20 24 39 22 12 44 36 2 21 14', found: 'Case #2: IMPOSSIBLE'