이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define inf 1000000007
#define llmax LLONG_MAX
#define pi 3.141592653589793238462643383279502884197169399
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
ll ncr(int n, int r)
{
if (n < r) return 0;
long long p = 1, k = 1;
if (n - r < r)
r = n - r;
if (r != 0) {
while (r) {
p *= n;
k *= r;
long long m = __gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
}
else
p = 1;
return p;
}
vector <ll> vcreate(int n){
vector <ll> v(n);
for (int i = 0; i < n; i++)
{
cin>>v[i];
}
return v;
}
void dfs(vector<vector<char>>&v, char z, int x, int y)
{
char find;
if(z=='R')
{
v[x][y]='F';
find='R';
}
else
{
v[x][y]='R';
find = 'F';
}
int h = v.size();
int w = v[0].size();
int dx[] = {-1, 1, 0, 0};
int dy[] = {0,0,-1,1};
for(int i = 0; i<4; i++)
{
if(x+dx[i]>=0 and x+dx[i]<h and y+dy[i]>=0 and y+dy[i]<w and v[x+dx[i]][y+dy[i]]==find)
{
dfs(v, z, x+dx[i], y+dy[i]);
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int h, w; cin>>h>>w;
vector<vector<char>>v(h, vector<char>(w));
for(int i = 0; i<h; i++)
{
for(int j = 0; j<w; j++)
{
cin>>v[i][j];
}
}
int ans = 1;
while(true)
{
char z = v[0][0];
dfs(v, z, 0, 0);
ans++;
set<char> s;
for(int i =0; i<h; i++)
{
for(int j = 0; j<w; j++)
{
if(v[i][j]!='.') s.insert(v[i][j]);
}
}
if(s.size()==1) break;
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |