Submission #898087

#TimeUsernameProblemLanguageResultExecution timeMemory
898087andrei_iorgulescuDango Maker (JOI18_dango_maker)C++14
13 / 100
1 ms2512 KiB
#include <bits/stdc++.h>

using namespace std;

int n,m;
char a[3005][3005];
bool viz[3005][3005];
bool viz2[3005][3005];
vector<pair<int,int>>poz;

void dfs(int l,int c)
{
    viz[l][c] = true;
    poz.push_back({l,c});
    if (a[l][c] == 'R')
    {
        if (c + 1 <= m and !viz[l][c + 1] and a[l][c + 1] == 'G')
            dfs(l,c + 1);
        if (l + 1 <= n and !viz[l + 1][c] and a[l + 1][c] == 'G')
            dfs(l + 1,c);
    }
    else if (a[l][c] == 'W')
    {
        if (c - 1 >= 1 and !viz[l][c - 1] and a[l][c - 1] == 'G')
            dfs(l,c - 1);
        if (l - 1 >= 1 and !viz[l - 1][c] and a[l - 1][c] == 'G')
            dfs(l - 1,c);
    }
    else
    {
        if (c + 1 <= m and !viz[l][c + 1] and a[l][c + 1] == 'W')
            dfs(l,c + 1);
        if (l + 1 <= n and !viz[l + 1][c] and a[l + 1][c] == 'W')
            dfs(l + 1,c);
        if (c - 1 >= 1 and !viz[l][c - 1] and a[l][c - 1] == 'R')
            dfs(l,c - 1);
        if (l - 1 >= 1 and !viz[l - 1][c] and a[l - 1][c] == 'R')
            dfs(l - 1,c);
    }
}

bool cmpl(pair<int,int> A, pair<int,int> B)
{
    if (A.first != B.first)
        return A.first < B.first;
    return A.second < B.second;
}

bool cmpc(pair<int,int> A, pair<int,int> B)
{
    if (A.second != B.second)
        return A.second < B.second;
    return A.first < B.first;
}

int solve1()
{
    for (auto it : poz)
        viz2[it.first][it.second] = false;
    //sort(poz.begin(),poz.end(),cmpl);
    int ans = 0;
    for (int i = 0; i < poz.size(); i++)
    {
        int l = poz[i].first,c = poz[i].second;
        if (c + 2 <= m and a[l][c] == 'R' and a[l][c + 1] == 'G' and a[l][c + 2] == 'W' and !viz2[l][c] and !viz2[l][c + 1] and !viz2[l][c + 2])
        {
            ans++;
            viz2[l][c] = viz2[l][c + 1] = viz2[l][c + 2] = true;
        }
    }
    for (int i = 0; i < poz.size(); i++)
    {
        int l = poz[i].first,c = poz[i].second;
        if (l + 2 <= n and a[l][c] == 'R' and a[l + 1][c] == 'G' and a[l + 2][c] == 'W' and !viz2[l][c] and !viz2[l + 1][c] and !viz2[l + 2][c])
        {
            ans++;
            viz2[l][c] = viz2[l + 1][c] = viz2[l + 2][c] = true;
        }
    }
    return ans;
}

int solve2()
{
    for (auto it : poz)
        viz2[it.first][it.second] = false;
    //sort(poz.begin(),poz.end(),cmpl);
    int ans = 0;
    for (int i = 0; i < poz.size(); i++)
    {
        int l = poz[i].first,c = poz[i].second;
        if (l + 2 <= n and a[l][c] == 'R' and a[l + 1][c] == 'G' and a[l + 2][c] == 'W' and !viz2[l][c] and !viz2[l + 1][c] and !viz2[l + 2][c])
        {
            ans++;
            viz2[l][c] = viz2[l + 1][c] = viz2[l + 2][c] = true;
        }
    }
    for (int i = 0; i < poz.size(); i++)
    {
        int l = poz[i].first,c = poz[i].second;
        if (c + 2 <= m and a[l][c] == 'R' and a[l][c + 1] == 'G' and a[l][c + 2] == 'W' and !viz2[l][c] and !viz2[l][c + 1] and !viz2[l][c + 2])
        {
            ans++;
            viz2[l][c] = viz2[l][c + 1] = viz2[l][c + 2] = true;
        }
    }
    return ans;
}

int solve(int l,int c)
{
    poz.clear();
    dfs(l,c);
    return max(solve1(),solve2());
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (!viz[i][j])
            {
                ans += solve(i,j);
            }
        }
    }
    cout << ans;
    return 0;
}
/*
4 3
WRW
RGW
GWW
WWW
*/

Compilation message (stderr)

dango_maker.cpp: In function 'int solve1()':
dango_maker.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < poz.size(); i++)
      |                     ~~^~~~~~~~~~~~
dango_maker.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 0; i < poz.size(); i++)
      |                     ~~^~~~~~~~~~~~
dango_maker.cpp: In function 'int solve2()':
dango_maker.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for (int i = 0; i < poz.size(); i++)
      |                     ~~^~~~~~~~~~~~
dango_maker.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for (int i = 0; i < poz.size(); i++)
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...