QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536362 | #833. Cells Blocking | ship2077 | WA | 111ms | 109952kb | C++14 | 1.8kb | 2024-08-29 08:50:36 | 2024-08-29 08:50:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=3005;long long ans;bool vis[M<<1];
pair<int,int>tmp[M<<1],way1[M<<1],way2[M<<1];
int n,m,cnt0,cnt1,a[M][M],rec1[M][M],rec2[M][M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void findway1(int x,int y){
while (x!=n||y!=m)
way1[x+y]=make_pair(x,y),
(rec2[x+1][y]?x:y)++;
way1[n+m]=make_pair(n,m);
}
void findway2(int x,int y){
while (x!=n||y!=m)
way2[x+y]=make_pair(x,y),
(rec2[x][y+1]?y:x)++;
way2[n+m]=make_pair(n,m);
}
void findway3(int x,int y){
while (x!=1||y!=1)
way1[x+y]=make_pair(x,y),
(rec1[x-1][y]?x:y)--;
way1[2]=make_pair(1,1);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=1;i<=n;i++){
string str;cin>>str;
for (int j=1;j<=m;j++)
cnt0+=a[i][j]=str[j-1]=='.';
}
rec1[1][1]=a[1][1];
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if (rec1[i][j]){
if (a[i+1][j]) rec1[i+1][j]=1;
if (a[i][j+1]) rec1[i][j+1]=1;
}
rec2[n][m]=a[n][m];
for (int i=n;i;i--)
for (int j=m;j;j--)
if (rec2[i][j]){
if (a[i-1][j]) rec2[i-1][j]=1;
if (a[i][j-1]) rec2[i][j-1]=1;
}
if (!rec1[n][m]) return printf("%lld\n",1ll*cnt0*(cnt0-1)/2),0;
findway1(1,1);findway2(1,1);
for (int i=2;i<=n+m;i++)
if (way1[i]==way2[i])
cnt1++,vis[i]=1;
ans=1ll*(cnt0-cnt1)*cnt1+1ll*cnt1*(cnt1-1)/2;
for (int i=2;i<=n+m;i++) tmp[i]=way1[i];
for (int i=n+m;i>1;i--)
if (!vis[i]){
auto [x,y]=tmp[i]; x--;y++;
while (!rec1[x][y]||!rec2[x][y])
x--,y++;
findway1(x,y);findway3(x,y);
for (int j=2;j<=n+m;j++)
if (!vis[j]&&way1[i]==way2[j])
ans++;
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8208kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7940kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7824kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9960kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 8080kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 111ms
memory: 109704kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 102ms
memory: 109804kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 108ms
memory: 109672kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 95ms
memory: 109736kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 105ms
memory: 109736kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: -100
Wrong Answer
time: 95ms
memory: 109952kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911520
result:
wrong answer 1st numbers differ - expected: '17911522', found: '17911520'