QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412760#6746. Merge the RectanglespWA 85ms195360kbC++173.0kb2024-05-16 19:01:002024-05-16 19:01:00

Judging History

你现在查看的是最新测评结果

  • [2024-05-16 19:01:00]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:195360kb
  • [2024-05-16 19:01:00]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
using namespace std;

const int N = 2e3;
char ma[N][N];

struct node
{
    int fg;
    int pos;
    int l, r;

    bool operator<(const node &o) const
    {
        if (fg != o.fg)
            return fg < o.fg;

        if (pos != o.pos)
            return pos < o.pos;

        if (l != o.l)
            return l < o.l;

        return r < o.r;
    }
};

map<node, int> num;
vector<node> arr[2][N][N];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;

    for (int i = 1; i < n; i++)
        for (int j = 1; j <= m; j++)
            cin >> ma[i][j];

    for (int i = 1; i < n; i++)
    {
        int l = -1;
        for (int j = 1; j <= m + 1; j++)
        {
            if (j == m + 1 || ma[i][j] == '0')
            {
                if (l != -1)
                {
                    node t = {1, i, l, j - 1};
                    num[t] = 2;
                    arr[1][i][j - 1].push_back(t);
                    arr[1][i][l].push_back(t);
                }
                l = -1;
            }
            else if (l == -1)
                l = j - 1;
        }
    }

    memset(0, sizeof ma, 0);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < m; j++)
            cin >> ma[i][j];

    for (int j = 1; j < m; j++)
    {
        int l = -1;
        for (int i = 1; i <= n + 1; i++)
        {
            if (i == n + 1 || ma[i][j] == '0')
            {
                if (l != -1)
                {
                    node t = {0, j, l, i - 1};
                    num[t] = 2;
                    arr[0][l][j].push_back(t);
                    arr[0][i - 1][j].push_back(t);
                }
                l = -1;
            }
            else if (l == -1)
                l = i - 1;
        }
    }

    queue<node> que;
    node t = {1, 0, 0, m};
    que.push(t);
    t = {1, n, 0, m};
    que.push(t);

    t = {0, 0, 0, n};
    que.push(t);
    t = {0, m, 0, n};
    que.push(t);

    while (que.size())
    {
        node t = que.front();
        que.pop();

        int pos = t.pos;

        for (int i = t.l; i <= t.r; i++)
        {
            int x, y;
            if (t.fg == 0)
                x = i, y = pos;
            else
                x = pos, y = i;

            for (auto c : arr[t.fg ^ 1][x][y])
            {
                if (num[c])
                {
                    num[c]--;
                    if (num[c] == 0)
                        que.push(c);
                }
            }
        }
    }

    for (auto c : num)
    {
        // cout << c.first.fg << " " << c.first.pos << " " << c.first.l << "|" << c.first.r << "   ";

        if (c.second > 0)
        {
            cout << "NO\n";
            return 0;
            // cout << "!";
        }

        // cout << "\n";
    }

    cout << "YES\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 29ms
memory: 191128kb

input:

3 4
0000
0111
101
101
110

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 24ms
memory: 192732kb

input:

3 3
110
011
01
11
10

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 59ms
memory: 194004kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 76ms
memory: 194344kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 83ms
memory: 194356kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #6:

score: 0
Accepted
time: 75ms
memory: 194596kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok answer is YES

Test #7:

score: 0
Accepted
time: 71ms
memory: 194260kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

NO

result:

ok answer is NO

Test #8:

score: 0
Accepted
time: 61ms
memory: 194440kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

NO

result:

ok answer is NO

Test #9:

score: 0
Accepted
time: 63ms
memory: 194496kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

NO

result:

ok answer is NO

Test #10:

score: 0
Accepted
time: 83ms
memory: 195360kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #11:

score: 0
Accepted
time: 85ms
memory: 194796kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #12:

score: -100
Wrong Answer
time: 54ms
memory: 194484kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

NO

result:

wrong answer expected YES, found NO