Submission #680252

# Submission time Handle Problem Language Result Execution time Memory
680252 2023-01-10T10:35:11 Z kakayoshi Dango Maker (JOI18_dango_maker) C++14
0 / 100
99 ms 212484 KB
#include <bits/stdc++.h>
using namespace std;
#define forw(i,a,b) for(int i=a;i<=b;i++)
#define forb(i,a,b) for(int i=a;i>=b;i--)
#define pu push
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
typedef long long int ll;
typedef pair<int,int> pii;
const ll maxN=3000+5;
const char base[3]={'R','G','W'};
const int tx[2]={1,0};
const int ty[2]={0,1};
bool vis[maxN][maxN],vis1[maxN];
int n,m,match[maxN*maxN],cnt;
char a[maxN][maxN];
vector <int> edge[maxN*maxN];
bool outmap(int x, int y)
{
    if (1<=x && x<=n)
    if (1<=y && y<=m) return 0;
    return 1;
}
bool matching(int u)
{
    for(int v:edge[u])
    if (!vis1[v])
    {
        vis1[v]=1;
        if (!match[v] || matching(match[v]))
        {
            match[v]=u;
            return 1;
        }
    }
    return 0;
}
void solve()
{
    cin>>n>>m;
    forw(i,1,n)
    forw(j,1,m)
        cin>>a[i][j];
    forw(i,1,n)
    forw(j,1,m)
    if (a[i][j]==base[0])
    forw(p,0,1)
    {
        int x=i; int y=j;
        bool flag=1;
        forw(k,1,2)
        {
            x+=tx[p]; y+=ty[p];
            if (outmap(x,y) || a[x][y]!=base[k]) flag=0;
        }
        if (!flag) continue;
        x=i; y=j;
        cnt++;
        if (vis[x][y])
        {
            edge[cnt].pb(vis[x][y]);
            edge[vis[x][y]].pb(cnt);
            cout<<cnt<<" "<<vis[x][y]<<endl;
        }
        vis[x][y]=cnt;
        forw(k,1,2)
        {
            x+=tx[p]; y+=ty[p];
            if (vis[x][y])
            {
                edge[cnt].pb(vis[x][y]);
                edge[vis[x][y]].pb(cnt);
            }
            vis[x][y]=cnt;
        }
    }
    int ans=0;
    forw(i,1,cnt)
    {
        memset(vis1,0,sizeof vis1);
        ans+=matching(i);
    }
    cout<<cnt-ans/2;
    return;
}
int main()
{
    ios::sync_with_stdio();
    cin.tie(0);
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 99 ms 212428 KB Output is correct
2 Correct 97 ms 212264 KB Output is correct
3 Correct 95 ms 212256 KB Output is correct
4 Correct 96 ms 212300 KB Output is correct
5 Correct 95 ms 212364 KB Output is correct
6 Incorrect 97 ms 212484 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 212428 KB Output is correct
2 Correct 97 ms 212264 KB Output is correct
3 Correct 95 ms 212256 KB Output is correct
4 Correct 96 ms 212300 KB Output is correct
5 Correct 95 ms 212364 KB Output is correct
6 Incorrect 97 ms 212484 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 212428 KB Output is correct
2 Correct 97 ms 212264 KB Output is correct
3 Correct 95 ms 212256 KB Output is correct
4 Correct 96 ms 212300 KB Output is correct
5 Correct 95 ms 212364 KB Output is correct
6 Incorrect 97 ms 212484 KB Output isn't correct
7 Halted 0 ms 0 KB -