답안 #680331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680331 2023-01-10T15:10:05 Z kakayoshi Dango Maker (JOI18_dango_maker) C++14
0 / 100
107 ms 221188 KB
#include <bits/stdc++.h>
using namespace std;

#define forw(i,a,b) for(ll i=a;i<=b;i++)
#define forb(i,a,b) for(ll 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()
#define minimize(a,b) a=min(a,b)
#define maximize(a,b) a=max(a,b)
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,pair<ll,ll> > plll;
const int maxN=3000+5;
const ll oo=1e18;
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*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("bruh.inp","r",stdin);
    //freopen("bruh.out","w",stdout);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 212360 KB Output is correct
2 Correct 107 ms 212360 KB Output is correct
3 Correct 102 ms 212260 KB Output is correct
4 Correct 99 ms 212372 KB Output is correct
5 Correct 99 ms 212352 KB Output is correct
6 Incorrect 105 ms 221188 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 212360 KB Output is correct
2 Correct 107 ms 212360 KB Output is correct
3 Correct 102 ms 212260 KB Output is correct
4 Correct 99 ms 212372 KB Output is correct
5 Correct 99 ms 212352 KB Output is correct
6 Incorrect 105 ms 221188 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 212360 KB Output is correct
2 Correct 107 ms 212360 KB Output is correct
3 Correct 102 ms 212260 KB Output is correct
4 Correct 99 ms 212372 KB Output is correct
5 Correct 99 ms 212352 KB Output is correct
6 Incorrect 105 ms 221188 KB Output isn't correct
7 Halted 0 ms 0 KB -