이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 3005, MAXX = 9e6 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
char a[MAXN][MAXN];
int cnt;
vector < int > v[MAXX];
void read()
{
cin >> n >> m;
for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= m; ++ j)
{
cin >> a[i][j];
}
}
}
int dir0[MAXN][MAXN], dir1[MAXN][MAXN];
int type[MAXX];
void precompute()
{
for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= m-2; ++ j)
{
if(a[i][j] == 'R' && a[i][j+1] == 'G' && a[i][j+2] == 'W')
{
cnt ++;
//g.push_back(tri(i, j, 0, cnt));
type[cnt] = 1;
dir0[i][j] = cnt;
dir0[i][j+1] = cnt;
dir0[i][j+2] = cnt;
}
}
}
for (int i = 1; i <= n-2; ++ i)
{
for (int j = 1; j <= m; ++ j)
{
if(a[i][j] == 'R' && a[i+1][j] == 'G' && a[i+2][j] == 'W')
{
cnt ++;
type[cnt] = 2;
//g.push_back(tri(i, j, 1, cnt));
dir1[i][j] = cnt;
dir1[i+1][j] = cnt;
dir1[i+2][j] = cnt;
}
}
}
for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= m; ++ j)
{
if(dir0[i][j] && dir1[i][j])
{
v[dir0[i][j]].push_back(dir1[i][j]);
v[dir1[i][j]].push_back(dir0[i][j]);
}
}
}
}
int used[MAXN];
int cnt1 = 0, cnt2 = 0;
void dfs(int beg)
{
used[beg] = 1;
if(type[beg] == 1)cnt1 ++;
else cnt2 ++;
int nb;
for (int i = 0; i < v[beg].size(); ++ i)
{
nb = v[beg][i];
if(!used[nb])dfs(nb);
}
}
void solve()
{
int ans = 0;
for (int i = 1; i <= cnt; ++ i)
{
if(!used[i])
{
cnt1 = 0;
cnt2 = 0;
dfs(i);
ans += max(cnt1, cnt2);
}
}
cout << ans << endl;
}
int main()
{
speed();
read();
precompute();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
dango_maker.cpp: In function 'void dfs(int)':
dango_maker.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int i = 0; i < v[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |