답안 #411293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411293 2021-05-25T00:50:53 Z ScarletS Nafta (COI15_nafta) C++17
34 / 100
1000 ms 93324 KB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

const int N = 2003;
int n,m,dp[N][N],C[N],ol[N][N],p[N][N],ct[N],l,r,t;
char s[N][N];
bitset<N> done[N];
vector<array<int,2>> d = {{0,-1},{0,1},{-1,0},{1,0}};

bool ok(int x, int y)
{
    if (0<x&&0<y&&x<=n&&y<=m&&s[x][y]!='.'&&!done[x][y])
        return 1;
    return 0;
}

void dfs(int x, int y)
{
    done[x][y]=1;
    l=min(l,y);
    r=max(r,y);
    t+=(s[x][y]-'0');
    for (auto i : d)
        if (ok(x+i[0],y+i[1]))
            dfs(x+i[0],y+i[1]);
}

void solve(int i, int l, int r, int optL, int optR)
{
    if (l>r)
        return;
    int m=l+(r-l)/2,best=-1,k=-1;
    for (int j=optL;j<=m;++j)
        if (best<dp[i-1][j-1]+C[m]-ol[j-1][m])
        {
            best=dp[i-1][j-1]+C[m]-ol[j-1][m];
            k=j;
        }
    dp[i][m]=best;
    solve(i,l,m-1,optL,k);
    solve(i,m+1,r,k,optR);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j)
            cin>>s[i][j];
    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j)
            if (ok(i,j))
            {
                t=0;
                l=j;
                r=j;
                dfs(i,j);
                ct[l]+=t;
                ct[r+1]-=t;
                p[l][l]+=t;
                p[l][r+1]-=t;
                // for (int k=l;k<=r;++k)
                //     ol[l][k]+=t;
            }
    for (int i=1;i<=m;++i)
    {
        ct[i]+=ct[i-1];
        C[i]+=ct[i];
    }
    for (int i=1;i<=n;++i)
        for (int j=i;j<=n;++j)
        {
            p[i][j]+=p[i][j-1];
            ol[i][j]=p[i][j]+ol[i-1][j];
            //cout<<i<<" "<<j<<" "<<ol[i][j]<<"\n";
        }
    // for (int i=1;i<=m;++i)
    //     for (int j=i;j<=m;++j)
    //         cout<<i<<" "<<j<<": "<<C[j]-ol[i-1][j]<<"\n";
    // return 0;
    for (int i=1;i<=m;++i)
    {
        solve(i,1,m,1,m);
        for (int j=2;j<=m;++j)
            dp[i][j]=max(dp[i][j-1],dp[i][j]);
        cout<<dp[i][m]<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 8 ms 5324 KB Output is correct
8 Correct 9 ms 5324 KB Output is correct
9 Correct 11 ms 6320 KB Output is correct
10 Correct 8 ms 5244 KB Output is correct
11 Correct 10 ms 5324 KB Output is correct
12 Correct 13 ms 5352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 8 ms 5324 KB Output is correct
8 Correct 9 ms 5324 KB Output is correct
9 Correct 11 ms 6320 KB Output is correct
10 Correct 8 ms 5244 KB Output is correct
11 Correct 10 ms 5324 KB Output is correct
12 Correct 13 ms 5352 KB Output is correct
13 Correct 358 ms 48068 KB Output is correct
14 Correct 400 ms 48068 KB Output is correct
15 Correct 451 ms 93324 KB Output is correct
16 Correct 324 ms 48068 KB Output is correct
17 Correct 750 ms 48048 KB Output is correct
18 Execution timed out 1061 ms 48044 KB Time limit exceeded