QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292503#7120. SoccerGoldenglow14270 1362ms337564kbC++147.2kb2023-12-28 06:18:282024-04-28 08:07:51

Judging History

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

  • [2024-04-28 08:07:51]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:1362ms
  • 内存:337564kb
  • [2023-12-28 06:18:28]
  • 评测
  • 测评结果:0
  • 用时:1446ms
  • 内存:337248kb
  • [2023-12-28 06:18:28]
  • 提交

answer

/*
ID: Victor Chen [mail_vi1]
PROG: Soccer Stadium
LANG: C++
*/

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cassert>
#include <ctime>

using namespace std;

const int Maxn = 2000;

typedef long long ll;

map<ll, bool> hash_mp;
map<ll, int> dp;

map<ll, bool> proc;

int n, ans;
bool mp[Maxn+10][Maxn+10];
int pre[Maxn+10][Maxn+10];

// int dp[Maxn+10][Maxn+10];

struct Rectangle
{
    int x, y; // The id signifies the rectangle.
    int l, r; // The left bound and the right bound.
    int u, d; // The upper bound and the lower bound.

    ll hsh;

    Rectangle(){}
    Rectangle(int x1, int y1, int x2, int y2)
    {
        u = x1; d = x2;
        l = y1; r = y2;
    }

    int find_area()
    {
        return (r-l+1) * (d-u+1);
    }

    void getHash()
    {
        hsh = (((((ll)l*Maxn)+r)*Maxn)+u)*Maxn+d;
    }
    bool exist()
    {
        return l != 0;
    }

    void print()
    {
        printf("%d %d %d %d\n", u, l, d, r);
    }
    void print(int x)
    {
        printf("%d %d %d %d: %d\n", u, l, d, r, x);
    }
}rec[Maxn+10][Maxn+10];

int cnt;
Rectangle ord[Maxn*Maxn+10];

bool cmp(Rectangle x, Rectangle y)
{
    if(x.d-x.u != y.d-y.u)
        return (x.d-x.u) < (y.d-y.u);
    else
        return (x.r-x.l) > (y.r-y.l);
}

int merge_area(Rectangle x, Rectangle y)
{
    return (min(x.d,y.d)-max(x.u,y.u)+1) * (min(x.r,y.r)-max(x.l,y.l)+1);
}
int find_sum(int x1, int y1, int x2, int y2)
{
    return pre[x2][y2] - pre[x2][y1-1] - pre[x1-1][y2] + pre[x1-1][y1-1]; 
}
Rectangle find_rect(int x, int y, int k)
{
    Rectangle ret = Rectangle();

    ret.u = x, ret.d = k;

    ret.l = ret.r = y;
    int l = 1, r = y, mid;
    while(l <= r)
    {
        mid = (l+r)/2;
        if(find_sum(x, mid, k, y) == 0)
        {
            r = mid - 1;
            ret.l = mid;
        }
        else
            l = mid + 1;
    }

    l = y, r = n;
    while(l <= r)
    {
        mid = (l+r)/2;
        if(find_sum(x, y, k, mid) == 0)
        {
            l = mid + 1;
            ret.r = mid;
        }
        else
            r = mid - 1;
    }

    return ret;
}
Rectangle find_up_rect(int x, int y, int k)
{
    Rectangle ret;

    ret.l = x, ret.r = y, ret.u = ret.d = k;

    int l = 1, r = k, mid;
    while(l <= r)
    {
        mid = (l+r)/2;
        if(find_sum(mid, x, k, y) == 0)
        {
            r = mid - 1;
            ret.u = mid;
        }
        else
            l = mid + 1;
    }

    return ret;
}
Rectangle find_down_rect(int x, int y, int k)
{
    Rectangle ret;

    ret.l = x, ret.r = y, ret.u = ret.d = k;

    int l = k, r = n, mid;
    while(l <= r)
    {
        mid = (l+r)/2;
        if(find_sum(k, x, mid, y) == 0)
        {
            l = mid + 1;
            ret.d = mid;
        }
        else
            r = mid - 1;
    }

    return ret;
}

int tp;
int nxt[Maxn+10][Maxn+10];
int prv[Maxn+10][Maxn+10];

double tm1, tm2, tm;

ll trans, trans1, trans2;

int biggest_stadium(int N, vector<vector<int>> F)
{
    n = N;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            mp[i][j] = F[i-1][j-1];
            pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + mp[i][j];
        }
    
    // printf("Checkpoint 0\n");

    for(int i=1; i<=n; i++)
    {
        int lst0 = n+1, lst1 = n+1;
        for(int j=n; j>=1; j--)
            if(mp[i][j] == 0)
            {
                nxt[i][j] = lst1;
                lst0 = j;
            }
            else
            {
                nxt[i][j] = lst0;
                lst1 = j;
            }
    }
    for(int i=1; i<=n; i++)
    {
        int pre0 = 0, pre1 = 0;
        for(int j=1; j<=n; j++)
            if(mp[i][j] == 0)
            {
                prv[i][j] = pre1;
                pre0 = j;
            }
            else
            {
                prv[i][j] = pre0;
                pre1 = j;
            }
    }

    // printf("Checkpoint 1\n");

    // The columns.
    for(int i=1; i<=n; i++)
    {
        tp = 0;
        for(int j=1; j<=n; j++)
            if(mp[j][i] == 1)
                tp = j;
            else
            {
                rec[i][j] = find_rect(tp+1, i, j);
                rec[i][j].x = i, rec[i][j].y = j;

                rec[i][j].getHash();

                if(rec[i][j].exist())
                {
                    ord[++cnt] = rec[i][j];
                    // hash_mp[rec[i][j].hsh] = true;

                    ord[cnt].getHash();
                }
            }
    }

    // find_rect(1, 2, 4).print();
    
    // for(int i=1; i<=n; i++)
    //     for(int j=1; j<=n; j++)
    //         rec[i][j].print();

    int tot = 0;

    // rec[4][3].print();
    // rec[3][3].print();
    // find_rect(1, 3, 3).print();

    // assert(n != 2000 || pre[n][n] <= 1);

    // printf("Checkpoint 2\n");

    for(int i=1; i<=cnt; i++)
    {
        // ord[i].print();
        trans++;

        dp[ord[i].hsh] = max(dp[ord[i].hsh], ord[i].find_area());

        if(ord[i].u != 1)
        {
            if(ord[i].x != ord[i].l && mp[ord[i].u-1][ord[i].x-1] == 0)
            {
                int ed = ord[i].x-1;
                int bg = prv[ord[i].u-1][ed] + 1;

                if(bg < ord[i].l) bg = ord[i].l;

                Rectangle nw = find_up_rect(bg, ed, ord[i].d);
                // Rectangle nw;
                nw.getHash();

                dp[nw.hsh] = max(dp[nw.hsh], dp[ord[i].hsh] + nw.find_area() - merge_area(ord[i], nw));
                trans1++;
            }
            if(ord[i].x != ord[i].r && mp[ord[i].u-1][ord[i].x+1] == 0)
            {
                int bg = ord[i].x+1;
                int ed = nxt[ord[i].u-1][bg] - 1;

                if(ed > ord[i].r) ed = ord[i].r;

                Rectangle nw = find_up_rect(bg, ed, ord[i].d);
                // Rectangle nw;
                nw.getHash();
                
                dp[nw.hsh] = max(dp[nw.hsh], dp[ord[i].hsh] + nw.find_area() - merge_area(ord[i], nw));
                trans1++;
            }
        }
        if(ord[i].d != n && mp[ord[i].d+1][ord[i].x] == 0)
        {
            Rectangle nw = rec[ord[i].x][ord[i].d+1];

            nw.getHash();
            
            dp[nw.hsh] = max(dp[nw.hsh], dp[ord[i].hsh] + nw.find_area() - merge_area(ord[i], nw));
            trans2++;
        }

        ans = max(ans, dp[ord[i].hsh]);
    }

    // printf("Final Checkpoint\n");

    // for(int i=1; i<=cnt; i++)
    //     ord[i].print(dp[ord[i].hsh]);

    // printf("%lld %lld %lld\n", trans, trans1, trans2);

    return ans;
}

// int N;
// vector<int> ept;
// vector<vector<int>> F;

// int main()
// {
//     freopen("staircase-large-06.in", "r", stdin);

//     scanf("%d", &N);
//     for(int i=0; i<N; i++)
//     {
//         F.push_back(ept);
//         for(int j=0; j<N; j++)
//         {
//             int x;
//             scanf("%d", &x);
//             F[i].push_back(x);
//         }
//     }

//     printf("%d\n", biggest_stadium(N, F));

//     return 0;
// }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 10040kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
1
0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
1

result:

ok ok

Test #2:

score: 6
Accepted
time: 0ms
memory: 10000kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 0
0 1 0
0 0 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
5

result:

ok ok

Test #3:

score: 1.5
Acceptable Answer
time: 5ms
memory: 19124kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
9847

result:

points 0.250 partial

Test #4:

score: 6
Accepted
time: 72ms
memory: 65536kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
236536

result:

ok ok

Test #5:

score: 6
Accepted
time: 1362ms
memory: 337564kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
3786181

result:

ok ok

Test #6:

score: 6
Accepted
time: 2ms
memory: 10112kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
9
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
80

result:

ok ok

Test #7:

score: 0
Wrong Answer
time: 2ms
memory: 10108kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
10
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
90

result:

wrong answer wrong

Subtask #2:

score: 0
Wrong Answer

Test #10:

score: 8
Accepted
time: 0ms
memory: 12052kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 0
0 1 0
0 1 1

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
5

result:

ok ok

Test #11:

score: 8
Accepted
time: 2ms
memory: 10300kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 0
0 1 1
0 0 1

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
5

result:

ok ok

Test #12:

score: 2
Acceptable Answer
time: 0ms
memory: 10012kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 1
0 0 0
1 1 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
4

result:

points 0.250 partial

Test #13:

score: 8
Accepted
time: 2ms
memory: 10296kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
1 0 0
1 0 1
0 0 1

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
4

result:

ok ok

Test #14:

score: 2
Acceptable Answer
time: 2ms
memory: 10064kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 1
0 0 0
1 0 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
5

result:

points 0.250 partial

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 10000kb

input:

R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L
3
0 0 1
0 0 1
0 0 0

output:

xlqtkQVzqzbOJxjzxlqsyVrlM2kqlbK0
OK
6

result:

wrong answer wrong

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%