QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386941#6746. Merge the Rectanglesk1nsomCompile Error//C++174.3kb2024-04-11 21:48:402024-04-11 21:48:40

Judging History

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

  • [2024-04-11 21:48:40]
  • 评测
  • [2024-04-11 21:48:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 300005
#define ednl '\n'
#define int long long
int n, m, a[1510][1510] = {0}, b[1510][1510] = {0}, cnt[1510][1510] = {0};
bool vis[1510][1510] = {0};
map<pair<pair<int, int>, pair<int, int>>, int> js;
struct ra
{
    int space, sx, sy, tx, ty;
    bool operator>(const ra &a) const
    {
        if (space == a.space)
            return sx > a.sx;
        return space > a.space;
    }
} tmp;
priority_queue<ra, vector<ra>, greater<ra>> q;
set<pair<pair<int, int>, pair<int, int>>> s1, s2;
vector<ra> v;
signed main()
{
    cin >> n >> m;
    for (int i = 1; i < n; i++)
        for (int j = 1; j <= m; j++)
        {
            char c;
            cin >> c;
            a[i][j] = c - '0';
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < m; j++)
        {
            char c;
            cin >> c;
            b[i][j] = c - '0';
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (!vis[i][j])
            {
                vis[i][j] = 1;
                int sx = i, sy = j, tx = i, ty = j;
                while (tx <= n && !a[tx][j])
                {
                    tx++;
                    if (tx > n)
                    {
                        tx--;
                        break;
                    }
                }
                while (ty <= m && !b[i][ty])
                {
                    ty++;
                    if (ty > m)
                    {
                        ty--;
                        break;
                    }
                }
                ra tmp = {(ty - sy + 1) * (tx - sx + 1), sx, sy, tx, ty};
                q.push(tmp);
                v.push_back(tmp);
                for (int t = i; t <= tx; t++)
                    for (int k = j; k <= ty; k++)
                        vis[t][k] = 1;
                s1.insert({{sx, tx}, {sy, ty}}); // s1记录
                s2.insert({{sy, ty}, {sx, tx}});
            }
    // for (auto u : v)
    // {
    // cout << u.space << ' ' << u.sx << ' ' << u.sy << ' ' << u.tx << ' ' << u.ty << endl;
    //}
    // cout << "分割\n";
    int num = 0;
    while (!q.empty())
    {
        ra u = q.top();
        q.pop();
        num++;
        s1.erase({{u.sx, u.tx}, {u.sy, u.ty}});
        s2.erase({{u.sy, u.ty}, {u.sx, u.tx}});
        if (num > 100000)
        {
            cout << "NO" return 0;
        }
        if (js[{{u.sx, u.sy}, {u.tx, u.ty}}])
            continue;
        // cout << u.space << ' ' << u.sx << ' ' << u.sy << ' ' << u.tx << ' ' << u.ty << endl;
        if (u.sx == 1 && u.sy == 1 && u.tx == n && u.ty == m)
        {
            cout << "YES" << endl;

            exit(0);
        }
        auto x = *s1.lower_bound({{u.sx, u.tx}, {0, 0}});
        // cout << x.first.first << ' ' << x.first.second << ' ' << x.second.first << ' ' << x.second.second << endl;
        if (x.first.first == u.sx && x.first.second == u.tx)
        {
            int ty = max(u.ty, x.second.second), tx = max(u.tx, x.first.second), sx = min(u.sx, x.first.first), sy = min(u.sy, x.second.first);
            // cout << sx << ' ' << sy << ' ' << tx << ' ' << ty << endl;
            q.push({(ty - sy + 1) * (tx - sx + 1), sx, sy, tx, ty});
            s1.erase(x);
            s1.insert({{sx, tx}, {sy, ty}}); // s1记录
            js[{{x.first.first, x.second.first}, {x.first.second, x.second.second}}] = 1;
            continue;
        }
        x = *s2.lower_bound({{u.sy, u.ty}, {0, 0}});
        // cout << x.first.first << ' ' << x.first.second << ' ' << x.second.first << ' ' << x.second.second << endl;
        if (x.first.first == u.sy && x.first.second == u.ty)
        {
            int ty = max(u.ty, x.first.second), tx = max(u.tx, x.second.second), sx = min(u.sx, x.second.first), sy = min(u.sy, x.first.first);
            q.push({(ty - sy + 1) * (tx - sx + 1), sx, sy, tx, ty});
            s2.erase(x);
            s2.insert({{sy, ty}, {sx, tx}});
            js[{{x.first.second, x.second.second}, {x.first.first, x.second.first}}] = 1;
            continue;
        }
        s1.insert({{u.sx, u.tx}, {u.sy, u.ty}});
        s2.insert({{u.sy, u.ty}, {u.sx, u.tx}});
    }
    cout << "NO" << endl;
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:87:25: error: expected ‘;’ before ‘return’
   87 |             cout << "NO" return 0;
      |                         ^~~~~~~
      |                         ;