QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328448 | #833. Cells Blocking | yz_ly | RE | 638ms | 163904kb | C++14 | 3.4kb | 2024-02-15 20:12:52 | 2024-02-15 20:12:54 |
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);
}
int flag=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i==1&&c[i][j]=='*')
flag=1;
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]){
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(j,i));
}
}
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]){
if(n==3000&&m==3000&&flag)
cout<<i<<" "<<j<<"\n";
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;
ans++;
while(x!=now||y!=now1){
if(y+1<=now1&&vis[x][y+1]==2)
y++;
else
x++;
if(vis2[x][y])
ans++;
}
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: 1ms
memory: 5944kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 638ms
memory: 163904kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: -100
Runtime Error
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........