QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574626#9319. Bull FarmlonelywolfWA 53ms3792kbC++203.0kb2024-09-18 23:18:352024-09-18 23:18:35

Judging History

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

  • [2024-09-18 23:18:35]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:3792kb
  • [2024-09-18 23:18:35]
  • 提交

answer

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

#define int long long  

int get() {
	char a, b;
	cin >> a >> b;
	return (a - 48) * 50 + (b - 48);
}

struct DSU {
    vector<int> f, siz;
    
    DSU() {}
    DSU(int n) {
        init(n);
    }
    
    void init(int n) {
        f.resize(n + 1);
        std::iota(f.begin() + 1, f.end(), 1);
        siz.assign(n + 1, 1);
    }
    
    int find(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        siz[x] += siz[y];
        f[y] = x;
        return true;
    }
    
    int size(int x) {
        return siz[find(x)];
    }
};


void solve() {
	int n, l, q;
	cin >> n >> l >> q;

	vector<vector<int>> t(l + 1, vector<int>(n + 1));
	for (int i = 1; i <= l; i++) {
		for (int j = 1; j <= n; j++) {
			t[i][j] = get();
		}
	}

	string s(q, '0');
	vector<vector<tuple<int, int, int>>> qry(l + 1);
	for (int i = 0; i < q; i++) {
		int a = get(), b = get(), c = get();
		if (a == b) {
			s[i] = '1';
		} else {
			qry[c].push_back({a, b, i});
		}
	}

	vector<vector<int>> adj(n + 1);
	vector<bitset<2010>> ans(n + 1);
	for (int i = 1; i <= n; i++) {
		ans[i].set(i);
	}
	DSU d(n);
	for (int k = 1; k <= l; k++) {
		auto &a = t[k];
		int sz = set(a.begin() + 1, a.end()).size();
		if (sz == n - 1) {
			vector<int> lst(n + 1);
			int x, y, z;
			for (int i = 1; i <= n; i++) {
				if (lst[a[i]] != 0) {
					x = lst[a[i]], y = i;
				}
				lst[a[i]] = i;
			}
			for (int i = 1; i <= n; i++) {
				if (lst[i] == 0) {
					z = i;
				}
			}
			adj[x].push_back(z);
			adj[y].push_back(z);
		} else if (sz == n) {
			vector<bool> vis(n + 1);
			for (int i = 1; i <= n; i++) {
				int now = i;
				while (!vis[now]) {
					// d.merge(now, a[now]);
					adj[now].push_back(a[now]);
					adj[a[now]].push_back(now);
					vis[now] = true;
					now = a[now];
				}
			}
		}
		vector<bool> vis(n + 1);
		function<void(int)> dfs = [&](int x) {
			// int fx = d.find(x);
			for (auto y : adj[x]) {
				if (!vis[y]) {
					vis[y] = true;
					dfs(y);
				}
				// int fy = d.find(y);
				ans[x] |= ans[y];
			}
		};
		// for (int i = 1; i <= n; i++) {
		// 	int f = d.find(i);
		// 	ans[f] |= ans[i];
		// }
		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				vis[i] = true;
				dfs(i);
			}
		}
		// for (int i = 1; i <= n; i++) {
		// 	int f = d.find(i);
		// 	ans[i] |= ans[f];
		// }
		for (auto [a, b, id] : qry[k]) {
			if (ans[a][b]) {
				s[id] = '1';
			}
		}
	}
	cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--) {
    	solve();
    }

    return 0;
}  

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

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: 0ms
memory: 3580kb

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: 53ms
memory: 3792kb

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 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101101111111111111111...1111111111111111101111111111111'