QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327941 | #833. Cells Blocking | xiang_xiang | AC ✓ | 737ms | 308176kb | C++14 | 2.5kb | 2024-02-15 15:38:12 | 2024-02-15 15:38:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inl inline
#define getchar cin.get
#define push_back emplace_back
const int N=3e3+5;
const int M=2e7+5;
const int mod=998244353;
const int inf=1e9;
const double eps=1e-6;
inl int read(){
int f=1,x=0;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return x*f;
}
template<typename T>
inl void read(T& x){
x=0;int f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
x*=f;
}
template<typename T,typename... Args>
inl void read(T& x,Args&... y){read(x),read(y...);}
int n,m,a[N][N],vis1[N][N],vis2[N][N],cnt;
vector<int>v[N<<1];
signed main(){
// freopen("1.out","w",stdout);
// freopen("1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
n=read(),m=read();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;cin>>c;
a[i][j]=c=='.';
}
}
vis1[1][1]=a[1][1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
vis1[i][j]|=vis1[i-1][j];
vis1[i][j]|=vis1[i][j-1];
vis1[i][j]&=a[i][j];
}
}
vis2[n][m]=a[n][m];
for(int i=n;i;i--){
for(int j=m;j;j--){
vis2[i][j]|=vis2[i+1][j];
vis2[i][j]|=vis2[i][j+1];
vis2[i][j]&=a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cnt+=a[i][j];
a[i][j]=vis1[i][j]&vis2[i][j];
if(a[i][j])v[i+j].push_back(i);
}
}
if(!vis1[n][m])return cout<<cnt*(cnt-1)/2<<endl,0;
int num=0,ans=0;
for(int i=2;i<=n+m;i++)
if(v[i].size()==1)ans+=cnt-++num;
for(int i=2;i<=n+m;i++){
if(v[i].size()==1)continue;
int l=v[i][v[i].size()-2],r=v[i].front();
ans+=l==r;
for(int j=i+1;j<=n+m;j++){
if(a[l+1][j-l-1])l++;
if(!a[r][j-r])r++;
if(l==r&&v[j].size()^1)ans++;
}
}
for(int i=2;i<=n+m;i++){
if(v[i].size()==1)continue;
int l=v[i].back(),r=v[i][1];
for(int j=i+1;j<=n+m;j++){
if(a[l+1][j-l-1])l++;
if(!a[r][j-r])r++;
if(l==r&&v[j].size()^1)ans++;
}
}
cout<<ans<<endl;
return 0;
}
/*
3 3
...
...
...
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3816kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 700ms
memory: 307208kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 670ms
memory: 307236kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 690ms
memory: 307144kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 693ms
memory: 306864kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 672ms
memory: 306780kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 669ms
memory: 306392kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 685ms
memory: 306104kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 665ms
memory: 306056kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 683ms
memory: 305520kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 737ms
memory: 305316kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 704ms
memory: 304596kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 641ms
memory: 276384kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 590ms
memory: 246236kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 111ms
memory: 215080kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 110ms
memory: 215072kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 124ms
memory: 215148kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 104ms
memory: 215004kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 682ms
memory: 307660kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 697ms
memory: 307676kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 686ms
memory: 308060kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 707ms
memory: 308176kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 676ms
memory: 308040kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 661ms
memory: 306920kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 673ms
memory: 307088kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 674ms
memory: 307604kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 691ms
memory: 305832kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 675ms
memory: 305668kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 645ms
memory: 305776kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 703ms
memory: 305700kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 700ms
memory: 305152kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 682ms
memory: 305816kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 684ms
memory: 305404kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 720ms
memory: 307864kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 700ms
memory: 305580kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 680ms
memory: 307660kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"