QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574306#9319. Bull FarmwangyuchenRE 42ms7920kbC++172.5kb2024-09-18 21:28:502024-09-18 21:28:51

Judging History

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

  • [2024-09-18 21:28:51]
  • 评测
  • 测评结果:RE
  • 用时:42ms
  • 内存:7920kb
  • [2024-09-18 21:28:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2010, Q = 1e6 + 10;

bitset<N> g[N];

vector<pair<int, int>> edges[N];
int to[N][N];
int n, l, q;

void getedge(int p) {
    vector<int> from[N];
    for (int i = 1; i <= n; i++)
        from[i].clear();
    for (int i = 1; i <= n; i++)
        from[to[p][i]].push_back(i);
    int p1 = -1, p2 = -1; bool flag = 1;
    for (int i = 1; flag && i <= n; i++) {
        if (from[i].size() > 2) flag = 0;
        else if (from[i].size() >= 2 && p1 != -1) flag = 0;
        else if (from[i].size() == 2) p1 = i;
        else if (from[i].size() == 0) p2 = i;
    }
    if (!flag) return;
    if (p1 == -1) {
        for (int i = 1; i <= n; i++)
            edges[p].emplace_back(i, to[p][i]);
    } else {
        int x = from[p1][0], y = from[p1][1], t = p2;
        edges[p].emplace_back(x, t);
        edges[p].emplace_back(y, t);
    }
}

void link(int u, int v) {
    if (g[u][v]) return;
    for (int i = 1; i <= n; i++)
        if (i == u || g[i][u]) g[i] |= g[v];
}

char str[N];

struct Query {
    int u, v, id;
    Query() { }
    Query(int x, int y, int z) : u(x), v(y), id(z) { }
};
vector<Query> qry[N];
char ans[Q];

void solve() {
    scanf("%d%d%d", &n, &l, &q);
    
    for (int i = 1; i <= n; i++) g[i].reset();
    for (int i = 0; i <= l; i++) {
        edges[i].clear();
        qry[i].clear();
    }
    for (int i = 1; i <= n; i++)
        memset(to[i], 0, sizeof(int) * (n + 1));
    for (int i = 1; i <= n; i++) g[i].set(i);
    
    for (int i = 1; i <= l; i++) {
        scanf("%s", str + 1);
        int tot = 1;
        for (int j = 1; j <= n; j++) {
            int x = (str[tot] - 48) * 50 + (str[tot + 1] - 48);
            tot += 2;
            to[i][j] = x;
        }
        getedge(i);
    }
    
    for (int i = 1; i <= q; i++) {
        scanf("%s", str + 1);
        int a = (str[1] - 48) * 50 + (str[2] - 48);
        int b = (str[3] - 48) * 50 + (str[4] - 48);
        int c = (str[5] - 48) * 50 + (str[6] - 48);
        qry[c].emplace_back(a, b, i);
    }
    
    for (int i = 0; i <= l; i++) {
        for (const auto & e : edges[i]) link(e.first, e.second);
        for (const auto & t : qry[i]) {
            // cout << t.u << ' ' << t.v << ' ' << g[t.u][t.v] << ' ' << i << endl;
            ans[t.id] = g[t.u][t.v] + '0';
        }
    }
    ans[q + 1] = 0;
    puts(ans + 1);
}

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

詳細信息

Test #1:

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

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

input:

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

output:

010101

result:

ok single line: '010101'

Test #3:

score: 0
Accepted
time: 42ms
memory: 4052kb

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:

ok 200 lines

Test #4:

score: -100
Runtime Error

input:

1
2000 1 1000000
M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...

output:


result: