이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
const int MAXN = 100;
vector<int> vin[MAXN][MAXN];
vector<int> g[MAXN * MAXN];
int used[MAXN * MAXN];
int nn[MAXN * MAXN];
int sm[MAXN * MAXN];
set<int> g2[MAXN * MAXN];
pair<int, int> dp[MAXN * MAXN];
void dfs3(int v, int p) {
used[v] = 3;
if (sm[v] > 1) {
dp[v].first = sm[v] / 2;
dp[v].second = sm[v] / 2;
} else {
dp[v].first = 1;
}
for (int u : g2[v]) {
if (u != p && used[u] != 3) {
dfs3(u, v);
dp[v].first += dp[u].second;
dp[v].second += max(dp[u].first, dp[u].second);
}
}
}
bool is_edge(int v, int u, int p) {
for (auto x : g[v]) {
if (x == u && x != p) {
return true;
}
}
return false;
}
bool check(int v) {
for (int i = 0; i < g[v].size(); i++) {
for (int j = i + 1; j < g[v].size(); j++) {
for (int u : g[g[v][i]]) {
if (is_edge(g[v][j], u, v)) {
return true;
}
}
}
}
return false;
}
void dfs(int v, vector<int> &comp) {
comp.push_back(v);
used[v] = 1;
for (int u : g[v]) {
if (!used[u]) {
dfs(u, comp);
}
}
}
void dfs2(int v, set<int> &in_c, int num) {
used[v] = 2;
nn[v] = num;
if (in_c.find(v) == in_c.end()) {
return;
}
for (int u : g[v]) {
if (used[u] != 2) {
dfs2(u, in_c, num);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> arr(n);
for (auto &x : arr) {
cin >> x;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i <= n - 3) {
if (arr[i][j] == 'R' && arr[i + 1][j] == 'G' && arr[i + 2][j] == 'W') {
vin[i][j].push_back(cnt);
vin[i + 1][j].push_back(cnt);
vin[i + 2][j].push_back(cnt);
cnt++;
}
}
if (j <= m - 3) {
if (arr[i][j] == 'R' && arr[i][j + 1] == 'G' && arr[i][j + 2] == 'W') {
vin[i][j].push_back(cnt);
vin[i][j + 1].push_back(cnt);
vin[i][j + 2].push_back(cnt);
cnt++;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (auto v : vin[i][j]) {
for (auto u : vin[i][j]) {
if (v != u) {
g[v].push_back(u);
}
}
}
}
}
int cnt2 = 0;
for (int i = 0; i < cnt; i++) {
if (!used[i]) {
vector<int> comp;
dfs(i, comp);
set<int> in_c;
for (auto x : comp) {
if (check(x)) {
in_c.insert(x);
}
}
for (auto x : comp) {
if (used[x] != 2) {
dfs2(x, in_c, cnt2);
cnt2++;
}
}
}
}
for (int i = 0; i < cnt; i++) {
sm[nn[i]]++;
for (int u : g[i]) {
if (nn[u] != nn[i]) {
g2[nn[i]].insert(nn[u]);
}
}
}
int res = 0;
for (int i = 0; i < cnt2; i++) {
if (used[i] != 3) {
dfs3(i, -1);
res += max(dp[i].first, dp[i].second);
}
}
cout << res << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
dango_maker.cpp: In function 'bool check(int)':
dango_maker.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++) {
~~^~~~~~~~~~~~~
dango_maker.cpp:44:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = i + 1; j < g[v].size(); j++) {
~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |