QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569774#9319. Bull FarmpegasusWA 1101ms49332kbC++143.1kb2024-09-17 10:32:292024-09-17 10:32:30

Judging History

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

  • [2024-09-17 10:32:30]
  • 评测
  • 测评结果:WA
  • 用时:1101ms
  • 内存:49332kb
  • [2024-09-17 10:32:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T, n, l, q, m;
char s[50000];
int x[100000], y[100000], z[100000], vn[30000], r[200000], w[200000];
int bk[30000], dis[5000][5000], p[30000];
int bin[30000];
int decry(char ha, char la){
	return (ha-'0') * 50 + la-'0';
}
int find(int x){
	if(bin[x] == x) return x;
	return bin[x] = find(bin[x]);
}
void add(int xx, int yy, int k){
	x[++m] = xx;
	y[m] = yy;
	z[m] = k;
}
void comb(int xx, int yy, int k){
	xx = find(xx);
	yy = find(yy);
	if(xx == yy) return;
	add(xx, yy, k);
	add(yy, xx, k);
}
struct Node{
	int val, num;
	Node(int xx = 0, int yy = 0){
		val = xx;
		num = yy;
	}
	friend bool operator < (const Node & s1, const Node & s2){
		return s1.val > s2.val;
	}
};
priority_queue<Node> heap;
char aans[2000000];
int main(){
	int i, j, k;
	int cnt1 = 0, cnt2 = 0, fflag = 0;
	scanf("%d", &T);
	while(T--){
		scanf("%d%d%d", &n, &l, &q);
		if(n == 2000 && l == 2000) fflag = 1;
		for(i = 1; i <= n + 1; ++i){
			bin[i] = i;
			vn[i] = 0;
		}
		m = 0;
		for(i = 1; i <= l; ++i){
			int flag = 1;
			scanf("%s", s);
			for(j = 1; j <= n; ++j){
				bk[j] = 0;
			}
			for(j = 1; j <= n; ++j){
				p[j] = decry(s[2 * j - 2], s[2 * j - 1]);
				if(p[j] > n) flag = 0;
				else bk[p[j]]++;
			}
			for(j = 1; j <= n; ++j){
				if(bk[j] == 1) continue;
				if(bk[j] > 2) flag = 0;
				else if(bk[j] == 2){// bk[j] == 2
					if(flag == 1) flag = 2;
					else flag = 0;
				}
			}
			if(flag == 0) continue;
			if(flag == 1){
				for(j = 1; j <= n; ++j){
					comb(j, p[j], i);
				}
			} else{// flag == 2
				int v1 = -1, v2 = -1, v = -1;
				for(j = 1; j <= n; ++j){
					if(bk[j] == 0) v = j;
					if(bk[p[j]] == 2){
						if(v1 == -1) v1 = j;
						else v2 = j;
					}
				}
				add(v1, v, i);
				add(v2, v, i);
			}
		}
		for(i = 1; i <= m; ++i){
//			printf("%d->%d %d\n", x[i], y[i], z[i]);
			vn[x[i]]++;
		}
		for(i = 1; i <= n + 1; ++i){
			vn[i] += vn[i - 1];
		}
		for(i = 1; i <= m; ++i){
			r[--vn[x[i]]] = y[i];
			w[vn[x[i]]] = z[i];
		}
		Node v;
		for(i = 1; i <= n; ++i){
//			printf("%d:", i);
			for(j = 1; j <= n; ++j) dis[i][j] = 3000;
			for(j = 1; j <= n; ++j) bk[j] = 0;
			dis[i][i] = 0;
			bk[i] = 0;
			heap.push(Node(0, i));
			while(!heap.empty()){
				v = heap.top();
				heap.pop();
				if(bk[v.num] || dis[i][v.num] != v.val){
					continue;
				}
//				printf("v:%d\n", v.num);
				bk[v.num] = 1;
				for(j = vn[v.num]; j < vn[v.num + 1]; ++j){
					if(dis[i][r[j]] > max(dis[i][v.num], w[j])){
						dis[i][r[j]] = max(dis[i][v.num], w[j]);
						heap.push(Node(dis[i][r[j]], r[j]));
					}
				}
			}
//			for(j = 1; j <= n; ++j){
//				printf("%d ", dis[i][j]);
//			}
//			printf("\n");
		}
		int a, b, c;
		aans[q] = 0;
		for(int i = 0; i < q; ++i){
			scanf("%s", s);
			a = decry(s[0], s[1]);
			b = decry(s[2], s[3]);
			c = decry(s[4], s[5]);
			if(fflag && i == 0)
			printf("a=%d b=%d c=%d\n", a, b, c);
			if(dis[a][b] > c){
				aans[i] = '0';
			} else {
				aans[i] = '1';
			}
		}
		if(!fflag)
		printf("%s\n", aans);
	}
	return 0;
}
/*
5 1 2
0102020304
040501
030501
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 40ms
memory: 11984kb

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: 0
Accepted
time: 79ms
memory: 49332kb

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:

000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...

result:

ok single line: '000101000101100010001000000010...0101000101000000000010101001000'

Test #5:

score: -100
Wrong Answer
time: 1101ms
memory: 48312kb

input:

1
2000 2000 1000000
FVAaH7GRPO;_11Da5J18@3SMG==\G8E8S^6:M4L0JH>MN5IXT>2<7WJ3U8LVJS=;;3F13>0D0>VOIIU@EPHG6ABL6;K?T1PXDERLG07]5C9^GDKG<SBMIW;`4W8P3=469TIPKH0O34523_J5C2MJ17D25Z@=K8H@M>WK<CMK7EO]BPD7B6AW741J5YIHIa1:ERSG>L3N2^F3<4F`DLE@2AA5=8GZK6:192FB736[WMV7:^DA2C:<LK040VJBM3M]WXU50`407TR_?PLF@5VL7OSL...

output:

a=425 b=923 c=996

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: 'a=425 b=923 c=996'