Submission #791215

# Submission time Handle Problem Language Result Execution time Memory
791215 2023-07-23T16:28:21 Z n3rm1n Dango Maker (JOI18_dango_maker) C++17
0 / 100
5 ms 5204 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 3005, MAXX = 1e5+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[MAXX];
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);
        }
    }
    assert(ans > 0);
    cout << ans << endl;
}
int main()
{
    speed();

    read();
    precompute();
    solve();
    return 0;
}
/**
10 10
RGWRWWRGWR
GWRGWRGWRG
WRGRRGWRGW
RGWRGWRGRR
GWRGWRGWRG
WRGWRGWRGW
RGGRGWGGWR
GWRGWRGWRG
RRGRWGWWGW
RGWRGWRGWR

10 10
RWRRGWRGWR
RWRGGRGWRG
WRGWRGWGGW
RGWWGWRGWR
WWRGWRWRRG
WRGRRGWRGW
RGWRWWRGWW
GWRGWRGWRG
WRGWGGWRGW
RGWRGWRGWR
 */

Compilation message

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
1 Runtime error 5 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -