提出詳細
ソースコード
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
#define answer(p) printf("Case #%lld:\n",(p)+1);
// #define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
string s,t;
ll d[200010],e[200010],dp[1001][1001];
int field[200][200];
int movexy[3] = {-1,0,1};
typedef struct pand{
int x,y;
}hito;
queue<pand> kansen;
void init(){
rep(i,0,200)rep(j,0,200)field[i][j] = 0;
}
int input(){
cin >> n >> m;
lep(i,1,m)lep(j,1,n){
cin >> field[i][j];
if(field[i][j] == 2){
kansen.push((pand){(int)i,(int)j});
}
}
return 0;
}
void bfs(){
while(!kansen.empty()){
pand now = kansen.front();kansen.pop();
rep(i,0,3)rep(j,0,3){
if(movexy[i] == 0 && movexy[j] == 0)continue;
if(field[now.x + movexy[i]][now.y + movexy[j]] == 0 || field[now.x + movexy[i]][now.y + movexy[j]] > 1)continue;
field[now.x + movexy[i]][now.y + movexy[j]] = field[now.x][now.y]+1;
kansen.push((pand){now.x + movexy[i],now.y + movexy[j]});
}
}
}
void ans(){
int p = 0;
bool flag_1 = false;
lep(i,0,m+1){
lep(j,0,n+1){
// cout << field[i][j] << " ";
p = max(field[i][j],p);
if(field[i][j] == 1)flag_1 = true;
}
// puts("");
}
if(flag_1)puts("ALIVE");
else print(p-2);
}
int main(){
int p;
cin >> p;
rep(q,0,p){
init();
input();
bfs();
answer(q);
ans();
}
return 0;
}
提出情報
提出出力結果
テストケース情報