답안 #1050809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050809 2024-08-09T14:42:43 Z 12345678 Toy (CEOI24_toy) C++17
9 / 100
9 ms 23292 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1505;

int n, k, l, r, c, dpl[nx][nx], dpr[nx][nx], dpup[nx][nx], dpdn[nx][nx], a, b, w, h, x, y, tmp;
pair<int, int> dsu[nx][nx];
char mp[nx][nx];

pair<int, int> find(pair<int, int> loc)
{
    if (dsu[loc.first][loc.second]==loc) return loc;
    return dsu[loc.first][loc.second]=find(dsu[loc.first][loc.second]);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>c>>r>>w>>h;
    cin>>tmp>>x>>tmp>>y;
    x++, y++;
    for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) cin>>mp[i][j], dsu[i][j]={i, j};
    for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) if (mp[i][j]=='*') a=i, b=j, mp[i][j]='.';
    //cout<<"debug "<<x<<' '<<y<<' '<<a<<' '<<b<<'\n';
    for (int i=1; i<=r; i++)
    {
        for (int j=1; j<=c; j++)
        {
            if (mp[i][j]=='X') continue;
            if (j==1||mp[i][j-1]=='X') dpl[i][j]=j;
            else dpl[i][j]=dpl[i][j-1];
        }
    }
    for (int i=1; i<=r; i++)
    {
        for (int j=c; j>=1; j--)
        {
            if (mp[i][j]=='X') continue;
            if (j==c||mp[i][j+1]=='X') dpr[i][j]=j;
            else dpr[i][j]=dpr[i][j+1];
        }
    }
    for (int j=1; j<=c; j++)
    {
        for (int i=1; i<=r; i++)
        {
            if (mp[i][j]=='X') continue;
            if (i==1||mp[i-1][j]=='X') dpup[i][j]=i;
            else dpup[i][j]=dpup[i-1][j];
        }
    }
    for (int j=1; j<=c; j++)
    {
        for (int i=r; i>=1; i--)
        {
            if (mp[i][j]=='X') continue;
            if (i==r||mp[i+1][j]=='X') dpdn[i][j]=i;
            else dpdn[i][j]=dpdn[i+1][j];
        }
    }
    for (int i=1; i<=r; i++)
    {
        for (int j=1; j<c; j++)
        {
            if (mp[i][j]=='X'||mp[i][j+1]=='X'||dpdn[i][j]-dpup[i][j]+1<h||dpdn[i][j+1]-dpup[i][j+1]+1<h) continue;
            int st=min({dpdn[i][j], dpdn[i][j+1], i+h-1});
            if (st-h+1>=dpup[i][j]&&st-h+1>=dpup[i][j+1])
            {
                //cout<<"merge col "<<i<<' '<<j<<'\n';
                auto pu=find({i, j}), pv=find({i, j+1});
                dsu[pu.first][pu.second]=pv;
            }
        }
    }
    for (int i=1; i<r; i++)
    {
        for (int j=1; j<=c; j++)
        {
            if (mp[i][j]=='X'||mp[i+1][j]=='X'||dpr[i][j]-dpl[i][j]+1<w||dpr[i+1][j]-dpl[i+1][j]+1<w) continue;
            int st=min({dpr[i][j], dpr[i+1][j], j+w-1});
            if (st-w+1>=dpl[i][j]&&st-w+1>=dpl[i+1][j])
            {
                //cout<<"merge row "<<i<<' '<<j<<'\n';
                auto pu=find({i, j}), pv=find({i+1, j});
                dsu[pu.first][pu.second]=pv;
            }
        }
    }
    if (find({x, y})==find({a, b})) cout<<"YES";
    else cout<<"NO";
}

/*
3 3 2 2
0 0 0 0
..X
...
X.*

2 3 2 3
0 1 0 0
.X
.*
.X

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Incorrect 0 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Incorrect 0 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 8 ms 9052 KB Output is correct
5 Correct 8 ms 9132 KB Output is correct
6 Correct 2 ms 2136 KB Output is correct
7 Correct 6 ms 9052 KB Output is correct
8 Correct 8 ms 9088 KB Output is correct
9 Correct 3 ms 3420 KB Output is correct
10 Correct 8 ms 9052 KB Output is correct
11 Correct 5 ms 9052 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 6 ms 9052 KB Output is correct
14 Correct 7 ms 9052 KB Output is correct
15 Correct 6 ms 8704 KB Output is correct
16 Correct 5 ms 8540 KB Output is correct
17 Correct 5 ms 8812 KB Output is correct
18 Correct 8 ms 9048 KB Output is correct
19 Correct 6 ms 8916 KB Output is correct
20 Correct 6 ms 9304 KB Output is correct
21 Correct 5 ms 9060 KB Output is correct
22 Correct 6 ms 9052 KB Output is correct
23 Correct 6 ms 9052 KB Output is correct
24 Correct 5 ms 9052 KB Output is correct
25 Correct 6 ms 9052 KB Output is correct
26 Correct 6 ms 9052 KB Output is correct
27 Correct 7 ms 9048 KB Output is correct
28 Correct 6 ms 9092 KB Output is correct
29 Correct 6 ms 9052 KB Output is correct
30 Correct 9 ms 8772 KB Output is correct
31 Correct 6 ms 8796 KB Output is correct
32 Correct 7 ms 23292 KB Output is correct
33 Correct 4 ms 23128 KB Output is correct
34 Correct 5 ms 23132 KB Output is correct
35 Correct 6 ms 8540 KB Output is correct
36 Correct 4 ms 8540 KB Output is correct
37 Correct 6 ms 8796 KB Output is correct
38 Correct 6 ms 8848 KB Output is correct
39 Correct 6 ms 8680 KB Output is correct
40 Correct 6 ms 8800 KB Output is correct
41 Correct 7 ms 8796 KB Output is correct
42 Correct 7 ms 9052 KB Output is correct
43 Correct 7 ms 9052 KB Output is correct
44 Correct 7 ms 9052 KB Output is correct
45 Correct 6 ms 9052 KB Output is correct
46 Correct 3 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Incorrect 0 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Incorrect 0 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -