QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571781#9319. Bull FarmLuckyblockWA 1ms3676kbC++203.2kb2024-09-18 08:34:472024-09-18 08:34:47

Judging History

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

  • [2024-09-18 08:34:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3676kb
  • [2024-09-18 08:34:47]
  • 提交

answer

//
/*
By:Luckyblock
*/
#include <bits/stdc++.h>
#define LL long long
#define pr std::pair
#define mp std::make_pair
const int kN = 2010;
//=============================================================
int n, l, q;
int fa[kN][2], into[kN], next[kN];
std::vector<pr<int, int> > edge[kN];
std::vector<int> node[kN];
int dis[kN][kN];
bool vis[kN];
//=============================================================
int get(char a_, char b_) {
  int ret = ((int) a_ - 48) * 50 + ((int) b_ - 48);
  return ret;
}
int find(int id_, int x_) {
  return fa[x_][id_] == x_ ? x_ : fa[x_][id_] = find(id_, fa[x_][id_]);
}
void merge(int id_, int x_, int y_) {
  int fx = find(id_, x_), fy = find(id_, y_);
  if (fx == fy) return ;
  fa[fx][id_] = fy;
}
void addedge(int u_, int v_, int w_) {
  edge[u_].push_back(mp(v_, w_));
}
void init() {
  for (int i = 1; i <= n; ++ i) edge[i].clear(), fa[i][0] = fa[i][1] = i;
  
  for (int time = 1; time <= l; ++ time) {
    std::string s; std::cin >> s;
    int flag = 0;
    for (int i = 1; i <= n; ++ i) {
      vis[i] = 0, into[i] = next[i] = 0, fa[i][1] = i;
    }
    for (int i = 0; i < 2 * n; i += 2) {
      int x = get(s[i], s[i + 1]);
      ++ into[x];
      if (into[x] == 2) ++ flag;
      if (into[x] == 3) flag = kN;
      merge(1, i / 2 + 1, x);
    }
    if (flag >= 2) continue;
    if (flag) {
      int u = 0, v1 = 0, v2 = 0;
      for (int i = 0; i < 2 * n; i += 2) {
        int x = get(s[i], s[i + 1]);
        if (into[x] == 0) u = x;
        if (into[x] == 2 && v1 != 0 && v2 == 0) v2 = i / 2 + 1;  
        if (into[x] == 2 && v1 == 0) v1 = i / 2 + 1;
      }
      for (int i = u; into[i] == 0; i = next[i]) {
        -- into[next[i]];
      }
      if (into[v1] == 0) std::swap(v1, v2);
      addedge(v1, u, time);
    } else {
      for (int i = 1; i <= n; ++ i) {
        if (find(0, find(1, i)) == find(0, i)) continue;
        addedge(i, find(1, i), time), addedge(find(1, i), i, time);
        merge(0, find(1, i), i);
      }
    }
  }
}
int query(int a_, int b_, int c_) {
  return dis[a_][b_] <= c_;
}
void dijkstra(int s_) {
  std::priority_queue <pr <int, int> > q;
  for (int i = 1; i <= n; ++ i) vis[i] = 0, dis[s_][i] = kN;
  dis[s_][s_] = 0;
  q.push(mp(0, s_));

  while (!q.empty()) {
    int u = q.top().second; q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto [v, w]: edge[u]) {
      if (dis[s_][v] > std::max(dis[s_][u], w)) {
        dis[s_][v] = std::max(dis[s_][u], w);
        q.push(mp(-dis[s_][v], v));
      }
    }
  }
}
//=============================================================
int main() {
  // freopen("1.txt", "r", stdin);
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  int T; std::cin >> T;
  while (T --) {
    std::cin >> n >> l >> q;
    init();
    for (int i = 1; i <= n; ++ i) dijkstra(i);

    while (q --) {
      std::string s; std::cin >> s;
      int a = get(s[0], s[1]), b = get(s[2], s[3]), c = get(s[4], s[5]);
      std::cout << query(a, b, c);
    }
    std::cout << "\n";
  }
  return 0;
}
/*
2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401
*/

详细

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

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

output:

000100

result:

wrong answer 1st lines differ - expected: '010101', found: '000100'