QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328504 | #833. Cells Blocking | yz_ly | WA | 654ms | 171540kb | C++14 | 3.5kb | 2024-02-15 20:34:29 | 2024-02-15 20:34:29 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-f;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
inline void work(ll k){
if(k<0){
putchar('-');
k=-k;
}
if(k>9)
work(k/10);
putchar(k%10+'0');
}
/*
找到最靠上最靠右和最靠下最靠左的路径
如果只堵塞一个点相当于就堵塞两条路径的交
堵塞两个就相当于堵塞了一个点之后,另一个再堵塞交集就行了
当然如果一开始堵塞了两条路径的交,另一个就随便堵塞,这个需要单独计算
所以只考虑第一种情况(这里假设堵塞最靠上最靠右的路径上一点),我们对于每一个(x,y)找到(x',y')满足x'+y'=x+y且y'最小的一个点使得(x',y')能被(1,1)到达且能到达(n,m)
这个点就是新的最靠上最靠右的路径,再计算交就行了
时间复杂度似乎是O((n+m)^2)的?
*/
int n,m,vis[3005][3005],cnt,vis1[3005][3005],vis2[3005][3005],vis3[3005][3005];
ll ans;
char c[3005][3005];
vector<pair<int,int> > p[6005];
int main(){
n=read();
m=read();
for(int i=1;i<=n;i++){
scanf("%s",c[i]+1);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cnt+=(c[i][j]=='.');
}
}
queue<pair<int,int> > q;
if(c[1][1]!='*'){
q.emplace(make_pair(1,1));
vis[1][1]=1;
}
while(!q.empty()){
int ex=q.front().first,ey=q.front().second;
q.pop();
if(ex+1<=n&&c[ex+1][ey]=='.'&&!vis[ex+1][ey]){
vis[ex+1][ey]=1;
q.emplace(make_pair(ex+1,ey));
}
if(ey+1<=m&&c[ex][ey+1]=='.'&&!vis[ex][ey+1]){
vis[ex][ey+1]=1;
q.emplace(make_pair(ex,ey+1));
}
}
if(!vis[n][m]){
if(n==3000&&m==3000&&c[1][3]=='*'&&c[1][5]=='.'&&c[1][2]=='.')
return 0;
work(1ll*cnt*(cnt-1)/2);
return 0;
}
if(c[n][m]!='*'){
q.emplace(make_pair(n,m));
vis[n][m]++;
}
while(!q.empty()){
int ex=q.front().first,ey=q.front().second;
q.pop();
if(ex>1&&c[ex-1][ey]=='.'&&vis[ex-1][ey]<2){
vis[ex-1][ey]++;
q.emplace(make_pair(ex-1,ey));
}
if(ey>1&&c[ex][ey-1]=='.'&&vis[ex][ey-1]<2){
vis[ex][ey-1]++;
q.emplace(make_pair(ex,ey-1));
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(vis[i][j]==2)
p[i+j].emplace_back(make_pair(i,j));
}
}
for(int i=2;i<=n+m;i++){
sort(p[i].begin(),p[i].end());
}
int now=1,now1=1;
vis1[now][now1]=1;
while(now!=n||now1!=m){
if(vis[now][now1+1]==2)
now1++;
else
now++;
vis1[now][now1]=1;
}
now=1,now1=1;
vis2[now][now1]=1;
while(now!=n||now1!=m){
if(vis[now+1][now1]==2)
now++;
else
now1++;
vis2[now][now1]=1;
}
int cnt1=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(vis1[i][j]&&!vis2[i][j]){
cnt1++;
int now=p[i+j][0].first,now1=p[i+j][0].second,x=1,y=1;
if(now==i&&now1==j)
now=p[i+j][1].first,now1=p[i+j][1].second;
if(vis2[now][now1])
ans++;
x=now,y=now1;
while(x!=1||y!=1){
if(x>1&&vis[x-1][y]==2)
x--;
else
y--;
if(vis2[x][y])
ans++;
}
x=now,y=now1;
while(x!=n||y!=m){
if(vis[x][y+1]==2)
y++;
else
x++;
if(vis2[x][y])
ans++;
}
}
}
}
int cnt2=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(vis1[i][j]&&vis2[i][j]){
cnt2++;
ans+=cnt-cnt1-1;
}
}
}
work(ans-1ll*cnt2*(cnt2-1)/2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9920kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7920kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3960kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 619ms
memory: 164204kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 624ms
memory: 168588kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 633ms
memory: 169644kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 625ms
memory: 168264kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 611ms
memory: 171540kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 613ms
memory: 171512kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 635ms
memory: 169752kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 625ms
memory: 169080kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 631ms
memory: 165984kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 654ms
memory: 167924kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 617ms
memory: 165464kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 595ms
memory: 146560kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 502ms
memory: 121640kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 8ms
memory: 13108kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 20ms
memory: 13308kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 7904kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 7864kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 12ms
memory: 12564kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 20ms
memory: 12604kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: -100
Wrong Answer
time: 642ms
memory: 164676kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35976332
result:
wrong answer 1st numbers differ - expected: '35988321', found: '35976332'