답안 #493309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493309 2021-12-10T21:31:53 Z inksamurai Zoo (COCI19_zoo) C++17
110 / 110
96 ms 6284 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3cSpNGp ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;

const int inf=1e9;

const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};

int main(){
_3cSpNGp;
	int h,w;
	cin>>h>>w;
	vec(vec(char)) a(h,vec(char)(w));
	rep(i,h)rep(j,w){
		cin>>a[i][j];
	}
	priority_queue<pii,vec(pii),greater<pii>> pq;
	pq.push({1,0});
	vi dp(h*w,inf);
	dp[0]=1;
	rep(i,h)rep(j,w){
		if(a[i][j]=='*') dp[i*w+j]=0;
	}
	while(sz(pq)){
		pii top=pq.top();
		int v=top.se,cost=top.fi;
		pq.pop();
		if(dp[v]!=cost) continue;
		int i=v/w,j=v%w;
		rep(dir,4){
			int nei=i+di[dir],nej=j+dj[dir];
			int u=nei*w+nej;
			if(min(nei,nej)>=0 and nei<h and nej<w){
				int now=cost;
				if(a[nei][nej]!=a[i][j]) now++;
				if(dp[u]>now){
					dp[u]=now;
					pq.push({now,u});
				}
			}
		}
	}
	cout<<*max_element(all(dp))<<"\n";
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 29 ms 5964 KB Output is correct
17 Correct 26 ms 6040 KB Output is correct
18 Correct 26 ms 6284 KB Output is correct
19 Correct 33 ms 6268 KB Output is correct
20 Correct 26 ms 6080 KB Output is correct
21 Correct 91 ms 5796 KB Output is correct
22 Correct 89 ms 5752 KB Output is correct
23 Correct 92 ms 5836 KB Output is correct
24 Correct 96 ms 6092 KB Output is correct
25 Correct 93 ms 5964 KB Output is correct
26 Correct 92 ms 5968 KB Output is correct
27 Correct 94 ms 5708 KB Output is correct
28 Correct 89 ms 5756 KB Output is correct
29 Correct 94 ms 6008 KB Output is correct
30 Correct 93 ms 5996 KB Output is correct