QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76361#2617. Browsing the CollectionretaliatorEliteTL 2452ms75972kbC++144.4kb2023-02-09 13:32:312023-02-09 13:32:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-09 13:32:31]
  • 评测
  • 测评结果:TL
  • 用时:2452ms
  • 内存:75972kb
  • [2023-02-09 13:32:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long read(){
	long long ret=0,neg=1;
	char ch;
	ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		neg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		ret=(ret<<1)+(ret<<3)+(ch^48);
		ch=getchar();
	}
	return ret*neg;
}
void write(long long x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
unordered_map<long long,int> mp;
long long invmp[20010];
int idx;
int Pre[20010][510],Suf[20010][510];
vector<int> mpos[20010];
int rs[7];


int n,m;
int str[510][7];

int dis[20010][510];
set<int> unvis[20010];
int ans[510][510];
queue<pair<int,int> > q;

void Upd(int cstr,int lb,int rb,int del){
	set<int>::iterator it;
	/*if(cstr==1&&lb==0&&rb==3){
		cout<<"!!!\n";
		for(it=unvis[cstr].begin();it!=unvis[cstr].end();it++)
			cout<<(*it)<<' ';
		cout<<endl;
	}*/
	while(1){
		it=unvis[cstr].lower_bound(lb+1);
		if(it==unvis[cstr].end()) break;
		if((*it)>rb) break;
		dis[cstr][(*it)]=del+1;
		q.push(make_pair(cstr,(*it)));
		unvis[cstr].erase(it);
	}
}

void bfs(int st){
	memset(dis,0x3f,sizeof(dis));
	for(int i=1;i<=idx;++i){
		//unvis[i].clear();
		for(int j=0;j<mpos[i].size();++j){
			unvis[i].insert(mpos[i][j]);
		}
	}
	while(q.empty()==false) q.pop();
	for(int s=0;s<(1<<m);++s){
		long long cur=0;
		for(int j=m;j>=1;--j){
			cur=cur*1000ll;
			cur+=str[st][j]*((s>>(j-1))&1);
		}
		cur=mp[cur];
		dis[cur][st]=0;
		unvis[cur].erase(st);
		q.push(make_pair(cur,st));
	}
	while(q.empty()==false){
		long long cstr,pos;
		cstr=(q.front()).first;
		pos=(q.front()).second;
		q.pop();
		int np;
		//cout<<st<<' '<<cstr<<' '<<pos<<' '<<dis[cstr][pos]<<endl;
		np=Pre[cstr][pos];
		if(dis[cstr][np]>10000000){
			dis[cstr][np]=dis[cstr][pos]+1;
			q.push(make_pair(cstr,np));
			unvis[cstr].erase(np);
		}
		np=Suf[cstr][pos];
		if(dis[cstr][np]>10000000){
			dis[cstr][np]=dis[cstr][pos]+1;
			q.push(make_pair(cstr,np));
			unvis[cstr].erase(np);
		}
		long long tmp=invmp[cstr];
		for(int j=1;j<=m;++j){
			rs[j]=tmp%1000;
			tmp=(tmp-rs[j])/1000;
		}
		tmp=1;
		for(int j=1;j<=m;++j,tmp*=1000ll){
			if(rs[j]!=0) continue;
			long long nst;
			nst=invmp[cstr]+1ll*tmp*str[pos][j];
			nst=mp[nst];
			if(dis[nst][pos]>10000000){
				dis[nst][pos]=dis[cstr][pos]+1;
				q.push(make_pair(nst,pos));
				unvis[nst].erase(pos);
			}
		}
		tmp=1;
		for(int j=1;j<=m;++j,tmp*=1000ll){
			if(rs[j]==0) continue;
			long long nst;
			nst=invmp[cstr]-1ll*tmp*str[pos][j];
			//if(st==4&&cstr==19&&pos==4){
			////	cout<<"AAA "<<nst<<' '<<endl;
			//}
			nst=mp[nst];
			int lim=Pre[cstr][pos];
			//Upd(nst,);
			if(lim>=pos){
				Upd(nst,0,pos,dis[cstr][pos]);
				Upd(nst,lim,n,dis[cstr][pos]);
			}
			else{
				Upd(nst,lim,pos,dis[cstr][pos]);
			}
		}
	}
	int ccc=mp[0];
	for(int i=1;i<=n;++i){
		ans[i][st]=dis[ccc][i];
	}
}

int main(){
	//freopen("string.in","r",stdin);
	//freopen("string.out","w",stdout);
	n=read();
	m=read();
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			str[i][j]=read();
		}
		for(int s=0;s<(1<<m);++s){
			long long cur=0;
			for(int j=m;j>=1;--j){
				cur=cur*1000ll;
				cur+=str[i][j]*((s>>(j-1))&1);
			}
			if(mp[cur]==0){
				++idx;
				mp[cur]=idx;
				invmp[idx]=cur;
			}
		}
	}
	for(int i=1;i<=idx;++i){
		long long tmp=invmp[i];
		for(int j=1;j<=m;++j){
			rs[j]=tmp%1000;
			tmp=(tmp-rs[j])/1000;
		}
		for(int j=1;j<=n;++j){
			bool flag=true;
			for(int k=1;k<=m;++k){
				if(rs[k]==0||rs[k]==str[j][k]);
				else{
					flag=false;
					break;
				}
			}
			if(flag) mpos[i].emplace_back(j);
		}
		int lim=mpos[i].size();
		for(int j=0;j<lim;++j){
			if(j==0) Pre[i][mpos[i][j]]=mpos[i][lim-1];
			else Pre[i][mpos[i][j]]=mpos[i][j-1];
			if(j==lim-1) Suf[i][mpos[i][j]]=mpos[i][0];
			else Suf[i][mpos[i][j]]=mpos[i][j+1];
		}
	}
	/*for(int i=1;i<=idx;++i){
		cout<<"id: "<<i<<' '<<invmp[i]<<endl;
		for(int j=0;j<mpos[i].size();++j)
			cout<<mpos[i][j]<<' ';
		cout<<endl;
		for(int j=0;j<mpos[i].size();++j)
			cout<<Pre[i][mpos[i][j]]<<' ';
		cout<<endl;

		for(int j=0;j<mpos[i].size();++j)
			cout<<Suf[i][mpos[i][j]]<<' ';
		cout<<endl;
	}*/
	for(int i=1;i<=n;++i){
		bfs(i);
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			write(ans[i][j]);
			putchar(' ');
		}
		putchar('\n');
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 52ms
memory: 44788kb

input:

9 3
5 3 7
5 3 4
5 3 7
5 3 2
5 3 4
5 3 7
2 3 7
5 3 7
2 3 7

output:

0 1 2 1 2 3 1 2 1 
1 0 1 1 2 2 1 3 2 
2 1 0 1 1 2 1 3 2 
3 2 1 0 1 1 1 3 2 
3 2 2 1 0 1 1 3 2 
3 1 2 1 1 0 1 2 2 
2 1 3 1 2 1 0 1 2 
2 1 3 1 2 2 1 0 1 
1 1 3 1 2 3 2 1 0 

result:

ok 81 numbers

Test #2:

score: 0
Accepted
time: 16ms
memory: 44680kb

input:

2 2
2 2
1 1

output:

0 1 
1 0 

result:

ok 4 number(s): "0 1 1 0"

Test #3:

score: 0
Accepted
time: 18ms
memory: 44824kb

input:

2 5
2 1 1 2 1
1 2 1 2 1

output:

0 1 
1 0 

result:

ok 4 number(s): "0 1 1 0"

Test #4:

score: 0
Accepted
time: 22ms
memory: 44612kb

input:

4 1
4
2
3
2

output:

0 1 1 1 
1 0 1 2 
1 1 0 1 
1 2 1 0 

result:

ok 16 numbers

Test #5:

score: 0
Accepted
time: 34ms
memory: 45072kb

input:

4 5
2 3 4 4 1
3 1 3 4 2
3 1 2 4 4
2 4 3 3 4

output:

0 1 1 1 
1 0 1 1 
1 1 0 1 
1 1 1 0 

result:

ok 16 numbers

Test #6:

score: 0
Accepted
time: 18ms
memory: 45160kb

input:

4 5
2 3 1 4 2
3 2 4 4 4
4 4 4 3 1
3 3 3 1 3

output:

0 1 1 1 
1 0 1 1 
1 1 0 1 
1 1 1 0 

result:

ok 16 numbers

Test #7:

score: 0
Accepted
time: 56ms
memory: 45568kb

input:

8 5
7 8 3 1 5
3 3 8 4 5
5 1 5 8 5
2 7 4 6 7
6 4 3 5 5
5 3 7 6 2
2 4 2 8 6
5 5 4 4 2

output:

0 1 1 1 1 1 1 1 
1 0 1 1 1 1 1 1 
1 1 0 1 1 1 1 1 
1 1 1 0 1 1 1 1 
1 1 1 1 0 1 1 1 
1 1 1 1 1 0 1 1 
1 1 1 1 1 1 0 1 
1 1 1 1 1 1 1 0 

result:

ok 64 numbers

Test #8:

score: 0
Accepted
time: 95ms
memory: 44756kb

input:

16 2
12 15
4 6
16 10
13 3
2 7
2 13
4 1
14 16
14 6
7 11
7 1
13 11
15 7
10 6
4 13
4 13

output:

0 1 1 1 1 1 1 1 2 1 2 2 1 1 2 1 
1 0 1 1 1 1 1 1 2 1 2 2 1 1 2 2 
1 1 0 1 1 1 1 1 1 1 2 2 1 1 2 2 
1 2 1 0 1 1 1 1 1 1 2 2 1 1 2 2 
1 2 1 1 0 1 1 1 1 1 2 1 1 1 2 2 
1 2 1 1 1 0 1 1 1 1 2 1 1 1 2 2 
1 2 1 1 1 1 0 1 1 1 2 1 1 1 1 2 
1 2 1 1 1 2 1 0 1 1 1 1 1 1 1 2 
1 2 1 1 1 2 2 1 0 1 1 1 1 1 1 2 
1 2...

result:

ok 256 numbers

Test #9:

score: 0
Accepted
time: 94ms
memory: 46660kb

input:

16 5
14 3 2 6 11
9 1 4 3 12
16 14 10 1 5
9 4 13 10 16
3 3 13 11 14
10 2 5 7 15
8 7 3 10 16
1 2 7 7 13
11 6 10 3 3
11 5 15 2 9
16 7 14 12 8
1 13 10 2 9
5 11 13 4 3
5 12 8 16 1
15 1 5 11 13
3 11 15 16 16

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 2 
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 2 
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 2 
1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 2 
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 
1 1...

result:

ok 256 numbers

Test #10:

score: 0
Accepted
time: 140ms
memory: 45256kb

input:

26 3
3 16 24
12 6 26
3 6 19
25 11 12
5 22 26
17 1 20
16 11 11
11 23 12
7 17 10
12 9 8
22 19 25
21 17 21
3 25 20
16 4 2
25 25 17
23 8 12
24 4 12
24 14 12
16 6 18
19 10 1
16 6 14
16 26 12
11 6 24
25 7 6
16 1 23
4 2 14

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 2 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok 676 numbers

Test #11:

score: 0
Accepted
time: 194ms
memory: 48532kb

input:

32 5
4 30 20 26 8
29 18 22 5 14
20 22 31 31 28
12 22 27 12 4
13 7 14 32 16
6 29 20 21 25
22 21 21 20 24
4 14 18 4 28
4 9 9 29 11
11 5 11 20 30
19 27 21 6 7
3 11 2 2 12
24 17 18 30 29
13 8 20 28 26
9 17 2 21 3
32 23 31 11 23
16 28 20 2 5
30 30 11 29 6
15 21 30 17 32
15 18 13 19 25
24 17 26 18 4
23 21...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 1024 numbers

Test #12:

score: 0
Accepted
time: 204ms
memory: 45120kb

input:

34 2
26 17
32 10
13 8
14 11
17 30
9 32
31 28
20 23
5 25
34 2
32 22
6 7
8 32
17 11
7 5
33 10
6 19
24 5
28 20
27 8
3 25
20 26
3 6
26 25
30 8
23 19
23 27
12 13
13 17
18 34
8 11
8 24
25 22
24 21

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 
2 1 0 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 
2 2 1 0 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 
2 2 2 1 0 1 1 1 1 1 1 1 ...

result:

ok 1156 numbers

Test #13:

score: 0
Accepted
time: 399ms
memory: 52388kb

input:

64 5
4 16 39 57 15
38 19 6 30 35
24 21 29 50 34
7 18 44 10 24
48 8 51 46 48
38 7 7 6 13
5 29 14 6 44
42 57 49 22 38
53 24 29 42 46
37 34 54 44 55
18 59 38 55 13
46 61 61 53 35
30 54 47 25 51
15 13 47 63 48
34 12 30 3 37
22 43 47 3 61
39 6 62 41 26
30 26 2 14 48
1 3 9 43 44
47 40 53 18 31
19 26 41 42...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 4096 numbers

Test #14:

score: 0
Accepted
time: 589ms
memory: 47360kb

input:

100 3
75 52 18
93 63 78
21 36 95
39 3 64
79 91 97
39 30 41
3 86 24
97 70 70
98 95 12
93 29 51
4 84 49
48 36 5
34 89 86
6 83 21
8 89 14
64 87 57
86 72 69
72 86 56
5 32 54
9 66 12
99 86 14
11 60 56
96 4 71
59 32 46
32 74 98
89 16 37
61 44 76
55 32 1
41 41 63
39 59 73
84 7 87
56 64 81
44 94 41
72 73 12...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 2 2 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok 10000 numbers

Test #15:

score: 0
Accepted
time: 956ms
memory: 60420kb

input:

128 5
122 18 15 41 30
78 109 50 118 101
34 110 71 93 99
98 30 54 126 13
91 99 108 58 97
27 38 75 54 33
47 82 25 25 82
97 23 73 58 117
50 90 92 71 121
39 121 111 73 94
53 8 119 89 80
51 6 40 86 8
90 93 80 35 40
55 30 29 9 114
78 104 61 22 87
83 55 41 55 31
31 66 24 15 8
28 79 38 6 29
57 95 124 104 3
...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok 16384 numbers

Test #16:

score: 0
Accepted
time: 1649ms
memory: 58596kb

input:

244 4
190 106 2 214
40 220 21 86
217 147 210 137
244 130 202 68
201 166 70 154
101 148 71 180
137 46 182 62
217 209 81 163
6 101 58 110
234 67 139 212
127 34 147 193
192 235 235 135
17 185 124 132
159 153 13 222
173 224 12 138
236 15 118 33
147 84 224 137
17 114 149 69
53 45 207 24
179 41 202 155
67...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 59536 numbers

Test #17:

score: 0
Accepted
time: 2452ms
memory: 75972kb

input:

256 5
197 131 211 151 128
133 74 92 247 210
81 173 69 34 33
213 153 59 17 54
95 193 174 114 210
10 154 196 59 95
107 101 91 211 149
74 68 84 179 120
191 54 173 3 33
26 218 211 90 69
229 236 137 153 183
250 75 60 18 42
157 249 173 55 142
216 29 111 254 106
76 192 2 108 124
105 33 12 55 64
182 84 91 9...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 65536 numbers

Test #18:

score: 0
Accepted
time: 1866ms
memory: 52424kb

input:

297 3
294 106 225
285 214 198
37 160 58
130 53 190
195 103 224
202 234 19
241 105 214
227 289 93
253 79 146
292 48 163
168 116 55
47 8 244
215 240 285
74 200 70
156 114 276
59 157 134
85 84 272
289 91 283
263 108 244
291 22 172
208 102 239
182 13 114
84 9 220
55 83 297
164 199 11
124 2 87
65 43 269
...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 ...

result:

ok 88209 numbers

Test #19:

score: -100
Time Limit Exceeded

input:

500 5
476 371 300 184 275
302 264 130 67 432
301 54 107 319 223
268 93 476 39 401
166 401 342 165 479
270 277 148 65 306
176 20 212 476 476
56 308 41 224 62
115 421 231 477 331
147 323 442 19 407
285 388 417 158 99
388 440 293 453 75
222 64 139 49 7
54 85 304 142 171
487 276 14 274 106
11 271 203 32...

output:


result: