QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570689#9319. Bull Farmyukino_yukinoshitaWA 59ms5988kbC++143.6kb2024-09-17 17:07:352024-09-17 17:07:37

Judging History

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

  • [2024-09-17 17:07:37]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:5988kb
  • [2024-09-17 17:07:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
const int M = 1e6 + 5;

int n, m, l, t[N][N];
int vis[N], flg[N], u1[N], u2[N], tt[N];
struct Qry {int a, b, c, id;} q[M];

bool cmp(Qry x, Qry y) {return x.c < y.c;}

bitset<2048> f[N];

int fa[N];
int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);}
void link(int x, int y)
{
    for(int i = 1; i <= n; i++)
        if(f[i][x]) f[i] |= f[y];
}
void merge(int x, int y)
{
    x = find(x), y = find(y);
    link(x, y), link(y, x);
    fa[y] = x;
}

void solve()
{
    cin >> n >> l >> m;
    for(int i = 1; i <= l; i++)
    {
        string s; cin >> s;
        for(int j = 1; j <= n; j++) vis[j] = 0;
        int cnt = 0;
        for(int j = 1; j <= n; j++)
        {
            t[i][j] = 50 * (int) (s[2 * j - 2] - '0') + (int) (s[2 * j - 1] - '0');
            // cout << t[i][j] << " \n"[j == n];
            if(vis[t[i][j]])
            {
                cnt++;
                if(cnt == 1) flg[i] = 1, u1[i] = j, u2[i] = vis[t[i][j]];
                else flg[i] = 2;
            }
            vis[t[i][j]] = j;
        }
        if(flg[i] == 1)
        {
            for(int j = 1; j <= n; j++) if(!vis[j])
            {
                tt[i] = j;
                break;
            }
        }
    }

    // cout << "\n";

    for(int i = 1; i <= m; i++)
    {
        string s; cin >> s;
        q[i].a = 50 * (int) (s[0] - '0') + (int) (s[1] - '0');
        q[i].b = 50 * (int) (s[2] - '0') + (int) (s[3] - '0');
        q[i].c = 50 * (int) (s[4] - '0') + (int) (s[5] - '0');
        q[i].id = i;
        // cerr << q[i].a << " " << q[i].b << " " << q[i].c << "\n";
    }
    sort(q + 1, q + m + 1, cmp);
    memset(vis, 0, sizeof(vis));
    for(int i = 1; i <= n; i++) f[i][i] = 1, fa[i] = i;

    string ans; ans.resize(m);
    for(int i = 1, cc = 1; i <= m; i++)
    {
        for(; cc <= q[i].c; cc++)
        {
            if(flg[cc] == 2) continue;
            if(flg[cc] == 1)
            {
                // f[u1[cc]] |= f[tt[cc]];
                // f[u2[cc]] |= f[tt[cc]];
                // for(int u = 1; u <= n; u++)
                // {
                //     if(f[u][u1[cc]] || f[u][u2[cc]]) f[u] |= f[tt[cc]];
                //     // if(f[u][u2[cc]]) f[u] |= f[tt[cc]];
                // }
                link(u1[cc], tt[cc]);
                link(u2[cc], tt[cc]);
                continue;
            }
            for(int u = 1; u <= n; u++) if(vis[u] == 0)
            {
                int st = u;
                bool ok = 0;
                bitset<2048> to, from;
                for(; vis[u] == 0; u = t[cc][u])
                {
                    vis[u] = 1, to |= f[u], from[u] = 1;
                    if(find(u) != find(st)) merge(st, u);
                }
                // for(; vis[u] == 1; u = t[cc][u])
                //     vis[u] = 2, f[u] = to;

                // for(; vis[u] == 1; u = t[cc][u])
                // {
                //     vis[u] = 2;
                //     if(f[u] != to) ok = 1;
                // }

                // if(ok) for(int u = 1; u <= n; u++)
                //     if((f[u] & from).any()) f[u] |= to;
            }
        }
        ans[q[i].id - 1] = (char) (f[q[i].a][q[i].b] + 48);
    }
    cout << ans << "\n";

    for(int i = 1; i <= n; i++) f[i].reset();
    for(int i = 1; i <= l; i++) flg[i] = 0;
    return;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int T; cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5700kb

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: 59ms
memory: 5988kb

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:

010000001101101111101010001101100000001111110101001110000100001011010101110111000011000100110011110100001001100011110101110101101010001010100100011110010101000000000111111010011111101001111010101010000111010111001111011000111010100101001001010100000110011011100000100100100010001010000001011101101110...

result:

wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '010000001101101111101010001101...1111110011111101001111010011101'