QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69756#1066. ROBOTSfeecle6418500 ✓338ms81976kbC++142.3kb2022-12-31 16:41:482022-12-31 16:41:48

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-31 16:41:48]
  • Judged
  • Verdict: 500
  • Time: 338ms
  • Memory: 81976kb
  • [2022-12-31 16:41:48]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
vector<int> g[250005];
struct Thing{
	int x,y,z;
}st[1000005];
int n,m,K,f[10][10][250005],vst[505][505][4],to[505][505][4],sign,top,*p;
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1},pl[250005];
char a[505][505];
int pos(int x,int y){
	return (x-1)*m+y;
}
int Do(int x,int y,int k){
	++sign,top=0;
	while(1){
		if(to[x][y][k]!=-1){
			for(int i=1;i<=top;i++)to[st[i].x][st[i].y][st[i].z]=to[x][y][k];
			return to[x][y][k];
		}
		st[++top]={x,y,k};
		int p=x+dx[k],q=y+dy[k];
		if(a[p][q]=='x'){
			for(int i=1;i<=top;i++)to[st[i].x][st[i].y][st[i].z]=pos(x,y);
			return pos(x,y);
		}
		x=p,y=q;
		if(a[p][q]=='A')k=(k+3)%4;
		if(a[p][q]=='C')k=(k+1)%4;
		if(vst[p][q][k]==sign)break;
		vst[p][q][k]=sign;
	}
	for(int i=1;i<=top;i++)to[st[i].x][st[i].y][st[i].z]=0;
	return 0;
}
void Do(int dis[]){
	p=dis,pl[0]=0;
	queue<int> q1,q2;
	for(int i=1;i<=n*m;i++)if(dis[i]<1e9)pl[++pl[0]]=i;
	sort(pl+1,pl+pl[0]+1,[](int x,int y){return p[x]<p[y];});
	for(int i=1;i<=pl[0];i++)q1.push(pl[i]);
	while(!q1.empty()||!q2.empty()){
		int x;
		if(q1.empty()||(q2.size()&&dis[q1.front()]>dis[q2.front()])){
			x=q2.front();
			q2.pop();
		}
		else {
			x=q1.front();
			q1.pop();
		}
		
		for(int y:g[x])if(dis[y]>dis[x]+1)dis[y]=dis[x]+1,q2.push(y);
	}
}
int main(){
	scanf("%d%d%d",&K,&n,&m),swap(n,m);
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=0;i<=n;i++)a[i][0]=a[i][m+1]='x';
	for(int i=0;i<=m;i++)a[0][i]=a[n+1][i]='x';
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)for(int k=0;k<4;k++)to[i][j][k]=-1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<4;k++){
				int w=Do(i,j,k);
				if(w&&w!=pos(i,j))g[pos(i,j)].push_back(w);
			}
		}
	}
	for(int i=1;i<=K;i++){
		for(int k=1;k<=n*m;k++)f[i][i][k]=1e9;
		for(int j=1;j<=n;j++)for(int k=1;k<=m;k++)if(a[j][k]=='0'+i)f[i][i][pos(j,k)]=0;
		Do(f[i][i]);
	}
	for(int len=2;len<=K;len++){
		for(int i=1;i+len-1<=K;i++){
			int j=i+len-1;
			for(int k=1;k<=n*m;k++)f[i][j][k]=1e9;
			for(int l=i;l<j;l++)for(int k=1;k<=n*m;k++)f[i][j][k]=min(f[i][j][k],f[i][l][k]+f[l+1][j][k]);
			Do(f[i][j]);
		}
	}
	int ans=1e9;
	for(int i=1;i<=n*m;i++)ans=min(ans,f[1][K][i]);
	if(ans==1e9)puts("-1");
	else cout<<ans;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 18480kb

input:

2 2 1
12

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 3ms
memory: 18724kb

input:

2 3 1
1x2

output:

-1

result:

ok single line: '-1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 17704kb

input:

2 4 1
.12.

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 1ms
memory: 18792kb

input:

2 10 10
...x...x.2
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
1x...x...x

output:

10

result:

ok single line: '10'

Test #5:

score: 0
Accepted
time: 4ms
memory: 19480kb

input:

2 10 10
..........
.xx..xx...
xx..xx..x.
x..xx..xx.
..xx..xx..
.xx..xx..x
xx..xx..xx
x..xx..xx2
..xx..xx..
1xx......x

output:

29

result:

ok single line: '29'

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 20
Accepted
time: 2ms
memory: 21208kb

input:

2 2 2
1C
.2

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 18844kb

input:

2 3 1
1A2

output:

2

result:

ok single line: '2'

Test #8:

score: 0
Accepted
time: 2ms
memory: 19556kb

input:

2 3 3
.x.
1CA
.x2

output:

2

result:

ok single line: '2'

Test #9:

score: 0
Accepted
time: 3ms
memory: 15844kb

input:

2 6 2
C1CA2A
CCCAAA

output:

6

result:

ok single line: '6'

Test #10:

score: 0
Accepted
time: 6ms
memory: 21340kb

input:

2 10 10
C.CxC.CxC2
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
1xA.AxA.Ax

output:

1

result:

ok single line: '1'

Subtask #3:

score: 30
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 30
Accepted
time: 31ms
memory: 53428kb

input:

9 296 298
2..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

47593

result:

ok single line: '47593'

Test #12:

score: 0
Accepted
time: 14ms
memory: 23472kb

input:

1 296 298
1..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 20ms
memory: 49812kb

input:

7 300 300
.x...x...x...x...x..4x...x...x...x...x...x...x...x..1x...x...x...x...x...x..5x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..6x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...

output:

438

result:

ok single line: '438'

Test #14:

score: 0
Accepted
time: 107ms
memory: 56664kb

input:

9 296 298
1AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...

output:

45376

result:

ok single line: '45376'

Test #15:

score: 0
Accepted
time: 24ms
memory: 53228kb

input:

9 296 298
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

-1

result:

ok single line: '-1'

Subtask #4:

score: 40
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 40
Accepted
time: 83ms
memory: 78000kb

input:

9 500 500
.....................................................................................................................................................................................................................................................................................................

output:

44

result:

ok single line: '44'

Test #17:

score: 0
Accepted
time: 338ms
memory: 77156kb

input:

9 496 500
2AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...

output:

138163

result:

ok single line: '138163'

Test #18:

score: 0
Accepted
time: 76ms
memory: 77620kb

input:

9 496 500
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 72ms
memory: 81976kb

input:

9 500 500
.x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..4x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...

output:

484

result:

ok single line: '484'

Test #20:

score: 0
Accepted
time: 191ms
memory: 79676kb

input:

9 496 500
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....

output:

126926

result:

ok single line: '126926'