QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567961#9319. Bull FarmawuWA 83ms9952kbC++142.7kb2024-09-16 14:49:512024-09-16 14:49:51

Judging History

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

  • [2024-09-16 14:49:51]
  • 评测
  • 测评结果:WA
  • 用时:83ms
  • 内存:9952kb
  • [2024-09-16 14:49:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

const i64 N = 2010, M = 1e6 + 10;

i64 n, l, Q;
i64 g[N][N];
bool f[N][N];
struct node
{
    i64 a, b, c, ans;
} q[M];
map<i64, vector<i64>> vec;

i64 get(char a, char b)
{
    // i64 t = ((i64)a - 48) * 50 + ((i64)b - 48);
    // cout << t << '\n';
    return ((i64)a - 48) * 50 + ((i64)b - 48);
}

// 添加 a -> b
void work(i64 a, i64 b)
{
    if (!f[a][b])
    {
        // cout << a << "  ->  " << b << '\n';
        f[a][b] = true;
        for (i64 c = 1; c <= n; c++)
        {
            // 更新 a -> 其他点
            if (f[b][c])
                f[a][c] = true;
            // 更新 其他点 -> b
            if (f[c][a])
                f[c][b] = true;
        }
    }
}

void solve()
{
    cin >> n >> l >> Q;
    for (i64 i = 0; i <= n; i++)
    {
        for (i64 j = 0; j <= n; j++)
            f[i][j] = false;
        f[i][i] = true;
        vec[i].clear();
    }

    for (i64 i = 1; i <= l; i++)
        for (i64 j = 1; j <= n; j++)
        {
            char a, b;
            cin >> a >> b;
            g[i][j] = get(a, b);
        }

    for (i64 i = 1; i <= Q; i++)
    {
        char ch1, ch2;
        cin >> ch1 >> ch2;
        q[i].a = get(ch1, ch2);
        cin >> ch1 >> ch2;
        q[i].b = get(ch1, ch2);
        cin >> ch1 >> ch2;
        q[i].c = get(ch1, ch2);
        vec[q[i].c].push_back(i);
    }

    for (i64 i = 0; i <= l; i++)
    {
        set<i64> S;
        for (i64 j = 1; j <= n; j++)
            S.insert(g[i][j]);
        if (S.size() == n)
        {
            for (i64 j = 1; j <= n; j++)
            {
                work(j, g[i][j]);
                work(g[i][j], j);
            }
        }
        else if (S.size() == n - 1)
        {
            i64 t = 1;
            while (S.count(t))
                t++;

            map<i64, i64> mp;
            for (i64 j = 1; j <= n; j++)
            {
                if (mp.count(g[i][j]))
                {
                    work(mp[g[i][j]], t);
                    work(j, t);
                    break;
                }
                mp[g[i][j]] = j;
            }
        }

        for (i64 u : vec[i])
        {
            // cout << "i: " << i << " u: " << u << '\n';
            // cout << "a: " << q[u].a << " b: " << q[u].b << '\n';
            q[u].ans = f[q[u].a][q[u].b];
        }
    }

    for (i64 i = 1; i <= Q; i++)
        cout << q[i].ans;
    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    i64 T = 1;
    cin >> T;
    while (T--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7764kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

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

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Wrong Answer
time: 83ms
memory: 9952kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111011101111011011111111111...1111110111111110111011110101111'