UVa 11624 Fire!

4200 단어 UVaGraph
누가 왜 첫 번째 코드가 AC이고 두 번째 코드가 WA인지 좀 봐줄래요--!발화 시간 bfs 그 판단 조건을 바꿨을 뿐이에요.
AC
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MP make_pair
#define PB push_back
#define SZ(x) ((int)(x).size())
#define REP(i,n) for (int _n=n,i=0; (i)<_n for="" _b="b,i=(a);i<=_b;++(i))" foreach="" __typeof="" it="(c).begin(),ite=(c).end();" int="" rint="" x="" if="" return="" typedef="" long="" ll="" const="" inf="~0U">>1;
using namespace std;

const int maxN=1010;
int t,n,m,dx[]={-1,1,0,0},dy[]={0,0,-1,1},sx,sy,ft[maxN][maxN];
char s[maxN][maxN];
bool vis[maxN][maxN];
struct Node{
	int time,x,y;
	Node(){}
	Node(int _time,int _x,int _y):time(_time),x(_x),y(_y){}
}no;
queue q;

int main(){
	t=rint();
	while(t--){
		n=rint(),m=rint();
		REP(i,n) scanf("%s",s[i]);
		REP(i,n) REP(j,m) {
			ft[i][j]=inf;
			if(s[i][j]=='F') ft[i][j]=0,q.push(Node(0,i,j));
			else if(s[i][j]=='J') sx=i,sy=j;
		}
		while(!q.empty()){
			no=q.front();
			q.pop();
			REP(i,4){
				int nx=no.x+dx[i],ny=no.y+dy[i];
				if(nx<0||nx>=n||ny<0||ny>=m||s[nx][ny]=='#'||ft[nx][ny]<=no.time+1) continue;
				ft[nx][ny]=no.time+1;
				q.push(Node(ft[nx][ny],nx,ny));
			}
		}/*
		REP(i,n){
			REP(j,m) cout<=n||ny<0||ny>=m){
					ans=no.time+1;
					break;
				}
				if(s[nx][ny]=='#'||vis[nx][ny]) continue;
				vis[nx][ny]=true;
				if(ft[nx][ny]<=no.time+1) continue;
				q.push(Node(no.time+1,nx,ny));
			}
		}
		if(ans==-1) puts("IMPOSSIBLE");
		else cout<

WA
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MP make_pair
#define PB push_back
#define SZ(x) ((int)(x).size())
#define REP(i,n) for (int _n=n,i=0; (i)<_n for="" _b="b,i=(a);i<=_b;++(i))" foreach="" __typeof="" it="(c).begin(),ite=(c).end();" int="" rint="" x="" if="" return="" typedef="" long="" ll="" const="" inf="~0U">>1;
using namespace std;

const int maxN=1010;
int t,n,m,dx[]={-1,1,0,0},dy[]={0,0,-1,1},sx,sy,ft[maxN][maxN];
char s[maxN][maxN];
bool vis[maxN][maxN];
struct Node{
	int time,x,y;
	Node(){}
	Node(int _time,int _x,int _y):time(_time),x(_x),y(_y){}
}no;
queue q;

int main(){
	t=rint();
	while(t--){
		n=rint(),m=rint();
		REP(i,n) scanf("%s",s[i]);
		memset(ft,-1,sizeof(ft));
		REP(i,n) REP(j,m) {
			if(s[i][j]=='F') ft[i][j]=0,q.push(Node(0,i,j));
			else if(s[i][j]=='J') sx=i,sy=j;
		}
		while(!q.empty()){
			no=q.front();
			q.pop();
			REP(i,4){
				int nx=no.x+dx[i],ny=no.y+dy[i];
				if(nx<0||nx>=n||ny<0||ny>=m||s[nx][ny]=='#') continue;
				if(ft[nx][ny]!=-1) continue;
				ft[nx][ny]=no.time+1;
				q.push(Node(ft[nx][ny],nx,ny));
			}
		}/*
		REP(i,n){
			REP(j,m) cout<=n||ny<0||ny>=m){
					ans=no.time+1;
					break;
				}
				if(s[nx][ny]=='#'||vis[nx][ny]) continue;
				vis[nx][ny]=true;
				if(ft[nx][ny]<=no.time+1) continue;
				q.push(Node(no.time+1,nx,ny));
			}
		}
		if(ans==-1) puts("IMPOSSIBLE");
		else cout<

좋은 웹페이지 즐겨찾기