QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328094#833. Cells BlockingkkioAC ✓158ms207252kbC++143.7kb2024-02-15 17:00:262024-02-15 17:00:27

Judging History

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

  • [2024-02-15 17:00:27]
  • 评测
  • 测评结果:AC
  • 用时:158ms
  • 内存:207252kb
  • [2024-02-15 17:00:26]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3005;
int n,m,fre,sec,val[maxn][maxn],zp[maxn][maxn],rp[maxn][maxn];
char s[maxn][maxn];
bool canv[maxn][maxn],bvis[maxn][maxn];
int v1[maxn][maxn],v2[maxn][maxn];
int tx[maxn<<1],ty[maxn<<1];
signed main()
{
  //  freopen("data.in","r",stdin);
  //  freopen("1.out","w",stdout);
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]=='.')fre++;
    for(int i=n;i>=1;i--)
        for(int j=m;j>=1;j--)
            if(s[i][j]=='*')continue;
            else 
            {
                if(i==n&&j==m)canv[i][j]=1;
                else 
                {
                    if(i!=n)canv[i][j]|=canv[i+1][j];
                    if(j!=m)canv[i][j]|=canv[i][j+1];
                }
            }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]=='*')continue;
            else 
            {
                if(i==1&&j==1)bvis[i][j]=1;
                else 
                {
                    if(i!=1)bvis[i][j]|=bvis[i-1][j];
                    if(j!=1)bvis[i][j]|=bvis[i][j-1];
                }
            }
    if(!canv[1][1])
    {
        cout<<1ll*fre*(fre-1)/2<<'\n';
        return 0;
    }
    long long ans=0;
    for(int nowx=1,nowy=1;1;)
    {
        v1[nowx][nowy]=1;
        if(nowx==n&&nowy==m)break;
        if(canv[nowx][nowy+1])nowy++;
        else nowx++;
       // cout<<nowx<<' '<<nowy<<'\n';
    }
    for(int nowx=1,nowy=1;1;)
    {
        v2[nowx][nowy]=1;
        if(nowx==n&&nowy==m)break;
        if(canv[nowx+1][nowy])nowx++;
        else nowy++;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(v1[i][j]&&v2[i][j])sec++;
    ans=1ll*sec*(fre-sec)+1ll*sec*(sec-1)/2;
  //  cout<<sec<<' '<<ans<<'\n';
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(canv[i][j]&&bvis[i][j]&&!v1[i][j])
                if(!tx[i+j]||(tx[i+j]>i))tx[i+j]=i,ty[i+j]=j;
    // for(int i=1;i<=n+m;i++)
    //     cout<<tx[i]<<' '<<ty[i]<<'\n';
    int sum=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(v1[i][j]&&(i!=n||j!=n))
            {
                //cout<<i<<' '<<j<<'\n';
                if(canv[i][j+1])
                {
                    if(v1[i][j+1]&&v2[i][j+1])continue;
                    if(!tx[i+j+1])sum++;
                    val[tx[i+j+1]][ty[i+j+1]]++;
                    zp[tx[i+j+1]][ty[i+j+1]]++;
                    rp[tx[i+j+1]][ty[i+j+1]]++;
                }
                else{
                    if(v1[i+1][j]&&v2[i+1][j])continue;
                    if(!tx[i+j+1])sum++;
                    val[tx[i+j+1]][ty[i+j+1]]++;
                    zp[tx[i+j+1]][ty[i+j+1]]++;
                    rp[tx[i+j+1]][ty[i+j+1]]++;
                }
            }
   
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        if(!canv[i][j])continue;
        else
        {
            if(v2[i][j]&&!v1[i][j])ans+=val[i][j];
            if(canv[i][j+1])val[i][j+1]+=val[i][j];
            else val[i+1][j]+=val[i][j];
        }
    for(int i=n;i>=1;i--)
        for(int j=m;j>=1;j--)
            if(!bvis[i][j])continue;
            else 
            {
                if(v2[i][j]&&!v1[i][j])ans+=zp[i][j]-rp[i][j];
                if(bvis[i-1][j])zp[i-1][j]+=zp[i][j];
                else zp[i][j-1]+=zp[i][j];
            }
    // for(int i=1;i<=n;i++,cout<<'\n')
    //     for(int j=1;j<=m;j++)
    //         cout<<zp[i][j]<<' ';

    ans+=1ll*(n+m-1-sec)*sum;
    cout<<ans<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3664kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

3 4
****
....
****

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

5 5
*....
.*.*.
*****
*.***
..*..

output:

66

result:

ok 1 number(s): "66"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

10 10
...***.*..
**...*.***
...***.*..
.**...*.*.
.*****..*.
..*.****.*
.**...****
..*..*.*.*
*.*.**....
....**...*

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 92ms
memory: 207008kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 111ms
memory: 207012kb

input:

3000 3000
...................................................................................................................*......................................................................................................................................................................*..........

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 132ms
memory: 207080kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 95ms
memory: 206812kb

input:

3000 3000
.........................................................................................................*...........................................................................................................................................................................................

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 74ms
memory: 207084kb

input:

3000 3000
......................................................................................................................................*........................................................................................................................................*.....................

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 104ms
memory: 206696kb

input:

3000 3000
...........................................*.........................................................................................................................................................................................................................................................

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 118ms
memory: 206964kb

input:

3000 3000
..............................*................................................................................................................*.....................................................................................................................................................

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 108ms
memory: 206860kb

input:

3000 3000
................................................................*....*................................................................................................................................................................................*..............................................

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 100ms
memory: 206696kb

input:

3000 3000
............................................................................................*.............................................................................*.....................................................................................................*....................

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 100ms
memory: 206604kb

input:

3000 3000
......................................*..........................................................................................................................................................*...................................................................................................

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 114ms
memory: 206652kb

input:

3000 3000
.................................................................................................................................................................................................................................*...................................................................

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 136ms
memory: 200152kb

input:

3000 3000
......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 158ms
memory: 179980kb

input:

3000 3000
..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 69ms
memory: 30220kb

input:

3000 3000
..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 96ms
memory: 29992kb

input:

3000 3000
.**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

score: 0
Accepted
time: 1ms
memory: 3676kb

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 94ms
memory: 30152kb

input:

3000 3000
.***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 28ms
memory: 29788kb

input:

3000 3000
*******************************************************************************************************************************************************************************************************************************************************.******************************************...

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 94ms
memory: 207140kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 112ms
memory: 207040kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 107ms
memory: 207124kb

input:

3000 3000
...**................................................................................................................................................................................................................................................................................................

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 120ms
memory: 206936kb

input:

3000 3000
...*.*...............................................................................................................................................................................................................................................................................................

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 96ms
memory: 207132kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 112ms
memory: 207112kb

input:

3000 3000
....**.*.............................................................................................................................................................................................................................................................................................

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 106ms
memory: 207044kb

input:

3000 3000
....****.............................................................................................................................................................................................................................................................................................

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 108ms
memory: 207140kb

input:

3000 3000
.........*...........................................................................................................................................................................................................................................................................................

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 95ms
memory: 206964kb

input:

3000 3000
.*.......*.............................................................................................................*................................................................................*............................................................................................

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

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

input:

3000 3000
.**...........................*..........................................................................................................................................*...........................................................................................................................

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 111ms
memory: 206904kb

input:

3000 3000
....*................................................................................................................................................................................................................................................................................................

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 115ms
memory: 206900kb

input:

3000 3000
..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 91ms
memory: 206692kb

input:

3000 3000
......*.........*...................................................................................*.....................................................................................................................*................................................*.........................

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 114ms
memory: 206676kb

input:

3000 3000
....*.**....*................*............................*..........*...............................................................................................................................................................................................................................

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 108ms
memory: 206872kb

input:

3000 3000
...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 97ms
memory: 207252kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

1 3000
........................................................................................................................................................................................................................................................................................................

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 92ms
memory: 206936kb

input:

3000 3000
.*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 99ms
memory: 207188kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35964327

result:

ok 1 number(s): "35964327"