QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572749#9319. Bull FarmswimsealWA 1ms3664kbC++172.0kb2024-09-18 16:13:162024-09-18 16:13:16

Judging History

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

  • [2024-09-18 16:13:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3664kb
  • [2024-09-18 16:13:16]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define pb push_back 
#define int long long

using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double, double> PDD;
 
const int N = 1e5 + 10, INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;
const double eps = 1e-9;

int n, l, Q;
int p[N];
int read(){
	char u,v;
	cin >> u >> v;
	//cout << u << " " << v << '\n';
	return (u - 48) * 50 + v - 48;
}

int find(int x){
	if(x != p[x]) p[x] = find(p[x]); 
	return p[x];
}

void solve(){
	cin >> n >> l >> Q;
	
	//cerr << n << '\n';
	//return;

	for (int i = 1; i <= n; i ++) p[i] = i;
	
	vector<vector<PII>> e(n + 1);

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

		int mul = 0, flag = 0, zero = -1;
		for (int j = 1; j <= n; j ++){
			if(cnt[j] == 2) mul ++;
			//if(cnt[j] > 2) flag ++;
			if(cnt[j] == 0) zero = j; 
		}

		if(flag || mul > 1) continue;
		if(mul == 0){
			for (int j = 1; j <= n; j ++){
				int a = j, b = t[j];
				int pa = find(a), pb = find(b);
				if(pa != pb){
					p[pa] = pb;
					e[t[j]].pb({j, i});
					e[j].pb({t[j], i});
				}
			}
		}
		else {
			for (int j = 1; j <= n; j ++){
				if(cnt[j] == 2){
					e[j].pb({zero, i});
				}
			}
		}
	}

	
	vector<vector<int>> d(n + 1, vector<int>(n + 1, 1e9));
	for (int i = 1; i <= n; i ++){
		d[i][i] = 0;
		vector<int> st(n + 1);
		queue<int> q;
		q.push(i);
    
		while(q.size()){
			auto u = q.front();
			q.pop();

			for(auto [v, w] : e[u]){
				if(d[i][v] > max(d[i][u], w)){
					d[i][v] = max(d[i][u], w);
					q.push(v);
				}
			}
		}
	}

	while(Q --){
		int a = read(), b = read(),c = read();
		if(d[a][b] <= c) cout << 1;
		else cout << 0;
	}

	cout << '\n';
}

signed main(){
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	int t = 1;cin >>t;
	while(t --) solve();
	return 0;
}

详细

Test #1:

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

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

input:

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

output:

111111

result:

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