QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#335557 | #833. Cells Blocking | AFewSuns | WA | 1ms | 3896kb | C++14 | 3.3kb | 2024-02-23 16:09:02 | 2024-02-23 16:10:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
ll n,m,f[3030][3030],g[3030][3030],ans=0;
bl ck1[3030][3030],ck2[3030][3030],pd1[3030][3030],pd2[3030][3030];
char s[3030][3030];
int main(){
n=read();
m=read();
fr(i,1,n) scanf("%s",s[i]+1);
if(s[1][1]=='*'||s[n][m]=='*'){
ll all0=0;
fr(i,1,n) fr(j,1,m) all0+=(s[i][j]=='.');
write(all0*(all0-1)/2);
return 0;
}
ck1[1][1]=1;
fr(i,1,n){
fr(j,1,m){
ck1[i][j]|=ck1[i-1][j]|ck1[i][j-1];
if(s[i][j]=='*') ck1[i][j]=0;
}
}
ck2[n][m]=1;
pfr(i,n,1){
pfr(j,m,1){
ck2[i][j]|=ck2[i+1][j]|ck2[i][j+1];
if(s[i][j]=='*') ck2[i][j]=0;
}
}
ll x=1,y=1;
pd1[1][1]=pd2[1][1]=1;
while(x<n||y<m){
if(ck2[x+1][y]) x++;
else y++;
pd1[x][y]=1;
}
x=y=1;
while(x<n||y<m){
if(ck2[x][y+1]) y++;
else x++;
pd2[x][y]=1;
}
ll all0=0,all=0;
fr(i,1,n) fr(j,1,m) if(s[i][j]=='.') all0++;
fr(i,1,n) fr(j,1,m) if(pd1[i][j]&&pd2[i][j]) all++;
ans=all*(all0-all)+all*(all-1)/2;
fr(i,1,n){
fr(j,1,m){
if(ck1[i][j-1]) f[i][j]=f[i][j-1]+(pd2[i][j]&&!pd1[i][j]);
else if(ck1[i-1][j]) f[i][j]=f[i-1][j]+(pd2[i][j]&&!pd1[i][j]);
}
}
pfr(i,n,1){
pfr(j,m,1){
if(ck2[i+1][j]) g[i][j]=g[i+1][j]+(pd2[i][j]&&!pd1[i][j]);
else if(ck2[i][j+1]) g[i][j]=g[i][j+1]+(pd2[i][j]&&!pd1[i][j]);
}
}
fr(i,1,n){
fr(j,1,m){
if(!pd1[i][j]) continue;
if(pd2[i][j]) continue;
x=i-1;
y=j+1;
while(!ck1[x][y]||!ck2[x][y]){
x--;
y++;
}
ans+=f[x][y]+g[x][y]-(pd2[x][y]&&!pd1[x][y]);
}
}
fr(i,1,n){
fr(j,1,m){
if(ck1[i-1][j]) f[i][j]=f[i-1][j]+(pd1[i][j]&&!pd2[i][j]);
else if(ck1[i][j-1]) f[i][j]=f[i][j-1]+(pd1[i][j]&&!pd2[i][j]);
}
}
pfr(i,n,1){
pfr(j,m,1){
if(ck2[i][j+1]) g[i][j]=g[i][j+1]+(pd1[i][j]&&!pd2[i][j]);
else if(ck2[i+1][j]) g[i][j]=g[i+1][j]+(pd1[i][j]&&!pd2[i][j]);
}
}
fr(i,1,n){
fr(j,1,m){
if(!pd2[i][j]) continue;
if(pd1[i][j]) continue;
x=i+1;
y=j-1;
while(!ck1[x][y]||!ck2[x][y]){
x++;
y--;
}
ans+=f[x][y]+g[x][y]-(pd1[x][y]&&!pd2[x][y]);
}
}
write(ans);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3896kb
input:
3 3 ... ... ...
output:
19
result:
wrong answer 1st numbers differ - expected: '17', found: '19'