제출 #1366760

#제출 시각아이디문제언어결과실행 시간메모리
1366760053thousand로봇 (APIO13_robots)C++20
0 / 100
81 ms229376 KiB
#include<bits/stdc++.h>
using namespace std;
	int a,b,c,d,e,f,g,xx,yy,dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}},gr[505][505][4][2],p[505][505][9][9];
	string chh[505];
	char ch[505][505];
	priority_queue<pair<int,pair<pair<int,int>,int>>>pp;
	queue<pair<pair<int,int>,int>>q[500500];
void dfs(int x,int y,int di){
	if(gr[x][y][di][0]!=-1) return;
	int dz=di;
	if(ch[x][y]=='C') dz=(dz+1)%4;
	if(ch[x][y]=='A') dz=(dz+3)%4;
	int nx=x+dir[dz][0],ny=y+dir[dz][1];
//	cout<<nx<<' '<<ny<<endl;
	if(ch[nx][ny]!='x' and nx>=0 and nx<xx and ny>=0 and ny<yy){
		dfs(nx,ny,dz);
		gr[x][y][di][0]=gr[nx][ny][dz][0];
		gr[x][y][di][1]=gr[nx][ny][dz][1];	
	}
	else gr[x][y][di][0]=x,gr[x][y][di][1]=y;
}
int main(){
//	for(int z=0;z<4;z++){
//		cout<<dir[z][0]<<' '<<dir[z][1]<<"\n";
//	}
    cin>>a>>xx>>yy;
    for(int i=0;i<yy;i++) cin>>chh[i];
    for(int i=0;i<xx;i++){
    	for(int h=0;h<yy;h++){
    		ch[i][h]=chh[h][i];
    		for(int z=0;z<4;z++){
    			gr[i][h][z][0]=-1;
    			gr[i][h][z][1]=-1;
			}
    		if(ch[i][h]>'0' and ch[i][h]<='9'){
    			q[0].push({{i,h},(ch[i][h]-'1')*11});
//    			pp.push({0,{{i,h},(ch[i][h]-'1')*11}});
			}
		}
	}
//	dfs(0,0,3);
	for(int i=0;i<xx;i++){
		for(int h=0;h<yy;h++){
			for(int z=0;z<9;z++){
				for(int zz=z;zz<9;zz++){
					p[i][h][z][zz]=-1e9;
				}
			}
			for(int z=0;z<4;z++){
				if(gr[i][h][z][0]==-1){
					dfs(i,h,z);
				}
//				cout<<i<<' '<<h<<' '<<z<<' '<<gr[i][h][z][0]<<' '<<gr[i][h][z][1]<<"\n";
			}
		}
	}
//	cout<<"\n\n\n\n";
	for(int i=0;i<xx*yy*2+10;i++){
		while(!q[i].empty()){
			int p1=i,x1=q[i].front().first.first,y1=q[i].front().first.second,rob=q[i].front().second;
			q[i].pop();
			if(rob==a-1){
				cout<<p1;
				return 0;
			}
			if(p[x1][y1][rob/10][rob%10]<0){
				p[x1][y1][rob/10][rob%10]=p1;
				int fn=rob/10,sn=rob%10;
//				cout<<x1<<' '<<y1<<' '<<' '<<fn<<' '<<sn<<' '<<p1<<"\n";
				for(int h=0;h<fn;h++){
					if(p[x1][y1][h][fn-1]>=0 and -p[x1][y1][h][sn]>p[x1][y1][h][fn-1]-p1){
						p[x1][y1][h][sn]=-p[x1][y1][h][fn-1]-p1;
						q[p[x1][y1][h][fn-1]+p1].push({{x1,y1},h*10+sn});
					}
				}
				for(int h=sn+1;h<a;h++){
					if(p[x1][y1][sn+1][h]>=0 and -p[x1][y1][fn][h]>p[x1][y1][sn+1][h]-p1){
						p[x1][y1][fn][h]=-p[x1][y1][sn+1][h]-p1;
						q[p[x1][y1][sn+1][h]+p1].push({{x1,y1},fn*10+h});
					}
				}
				for(int h=0;h<4;h++){
					int nx=gr[x1][y1][h][0],ny=gr[x1][y1][h][1];
					if(p[nx][ny][fn][sn]<0 and -p[nx][ny][fn][sn]>p1+1){
						p[nx][ny][fn][sn]=-p1-1;
						q[p1+1].push({{nx,ny},rob});
					}
				}
			}
		}
	}
	cout<<-1;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…