QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#13362 | #1995. Sprinklers 2: Return of the Alfalfa | Romatzyh | 100 ✓ | 62ms | 8680kb | C++14 | 2.3kb | 2021-09-10 22:41:21 | 2022-05-17 02:18:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}
cs int N=2005,iv=Inv(2),pv=mul(iv,iv);
int f[N],g[N];
char str[N][N];
int n,cnt;
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read();
for(int i=n;i;i--)readstring(str[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)cnt+=(str[i][j]!='W');
int v=ksm(2,cnt);
for(int i=0;i<n;i++)if(str[i+1][1]!='W')f[i]=mul(v,iv);
f[n]=v;
for(int t=2;t<=n;t++){
memcpy(g,f,sizeof(f));
int s=0;
for(int i=n;~i;i--){
if(str[i+1][t]!='W'&&(t!=n||str[i][t]!='W'))Add(f[i],s);
if(str[i][t-1]!='W')Add(s,mul(pv,g[i]));
}
}
int res=0;
for(int i=0;i<=n;i++)if(str[i][n]!='W'){
Add(res,mul(f[i],(i==0)?1:iv));
}cout<<res<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 6.25
Accepted
time: 3ms
memory: 5736kb
input:
2 .. ..
output:
28
result:
ok single line: '28'
Test #2:
score: 6.25
Accepted
time: 0ms
memory: 5712kb
input:
4 ..W. ..WW WW.. ...W
output:
2304
result:
ok single line: '2304'
Test #3:
score: 6.25
Accepted
time: 3ms
memory: 3612kb
input:
7 .WWWW.. W.WWWWW W.WW.W. WWWWWWW WWW.WWW WWWWWWW WW.WWW.
output:
1088
result:
ok single line: '1088'
Test #4:
score: 6.25
Accepted
time: 3ms
memory: 3596kb
input:
10 WWW..WWWWW WWWWWWWWWW WWWWWWWWWW WWWW.WWWWW WWWWWWWW.. WWWWWWWWWW WWWWWWWWWW WWWW.WWW.W WWWWWWWWW. W.WWWW.WWW
output:
256
result:
ok single line: '256'
Test #5:
score: 6.25
Accepted
time: 4ms
memory: 4128kb
input:
200 ..W...W.W..WWW....W...W..W........W..W.W...W.WW.WWW.WWW..W....WW.WW.........W..WW.WW..WW....WW...W..W.W.WW.WWW.W...W....W.WW.........W.W.WW.WWW...........W...W..W.....W..W.......W..WW.WW......W...WWW. W..WWWW.W......W.....W......WW.W.W....W.WW.W........WW...W...WW.W.W...W...W...WW.W.WW....W..WW....
output:
73928933
result:
ok single line: '73928933'
Test #6:
score: 6.25
Accepted
time: 0ms
memory: 4104kb
input:
200 ..W....W.W.W..W..W.W..WWW.WW...W...W...W.W.W.....WW....W..W..W..WW....W.....WWW..W.......WW.W..WW..W.WW.....W.W.W.W..W.WW..WW..W...W....WW...W.W...W.W.W....W............WW.W..W......W.W.......W.W..... W.....W...............W..W.....WWWWWWW.WW....W....WW.W...W...W....W.WW.WW..W.....W.WWWW..W.W......
output:
986875102
result:
ok single line: '986875102'
Test #7:
score: 6.25
Accepted
time: 2ms
memory: 3968kb
input:
200 .W.......W.........W.W.W.W..W.....W..WW.W.W.WWW...W..W..W...W..W.W.W..W..W..W.....W..W....W.W....WWW.W..W.WW..WW.....W.........W......WWW....W.WW..........WWW.W.W..........W..W..WWW.W...WW.....WW..... ..W.W.....W..W...WW....WWWW....WW......W.WWW.WW.W.......W....WW.WW.......W.W.W...WWWW......W..W...
output:
980557628
result:
ok single line: '980557628'
Test #8:
score: 6.25
Accepted
time: 4ms
memory: 4128kb
input:
200 W.WWW.....W...WWWW...WW..W.......WW...W.W.....W..W..W........WWWW.W.WW.W...WW.WW..WW......WW...WWW.......W...WW....W..W.....W.W..WWW.W.W..W......W...W...W.W..W.WW.W...W...W.W...W..W.WW.W..W...W..W.W.W WW.....W.W..W.W......W.W..WW...W...W..........W...W..W.W.W...W.W....WW.W.W.WW...WW.W..W...WWW.....
output:
135705039
result:
ok single line: '135705039'
Test #9:
score: 6.25
Accepted
time: 4ms
memory: 7716kb
input:
200 ..W.W..W.W.WW.WW.W.W...WW...W..W...W.WW.W.W......W....W.W.WW...WW.WW.WWW.W...W.......W.W.W..WW.WWW..W..WW......WW.W...WW...WW...WWW..W....W.WW.......W..W.W.....WWWW.W....WW...W....W..W...W....WW..W..W W......WWWW.....W..........WW..W.W.....W...W...WWW......WW.......WW...WW......W.WW.W...W...WW.W...
output:
153872030
result:
ok single line: '153872030'
Test #10:
score: 6.25
Accepted
time: 55ms
memory: 8528kb
input:
2000 W......WWWWW.W..WW......W.....WWW.......W.W.W..WW...W.....W..W..W....WWW.W.WWWW.W..W...W....W......W..WWW.WW......WW..W..W.......W.......WW..........W..WW..W..W..WWW.WW....W......W...WW.WW......W..WW......W.WW.W.W..W...W.....W.........WW.W...W...WW.WW..WWW..WW.W.WWWW....W.WW........WW.....W.W.....
output:
375172260
result:
ok single line: '375172260'
Test #11:
score: 6.25
Accepted
time: 57ms
memory: 8528kb
input:
2000 W.WW.....W..WW.................WWW..W....W.W.WWW...W.W........WW....W..W........W.W........W.......WW..WWW..W...WW..WW...WWWW..WWWW.W.......W....W...W...W.....W...WW...WWW...WW..W.WW..W....W.WW.........WWW.W..W...WW...WWW...WWW....W..W....WW....WW.W.........W...W...WWW..WW.............W...........
output:
831890193
result:
ok single line: '831890193'
Test #12:
score: 6.25
Accepted
time: 62ms
memory: 8680kb
input:
2000 .W....W.WW.W....WW..W.W....W.WW.W....WW.WW.....WW..W.W.........W.W.WWWW.WWWWWWWW.W....W.W..WW...W..W..W...W...W.W.W..W...WWW...WWW.....WW...W..W..W.W...........W.W..........WW...WWW..W..W..W..W.....W.W..W....WW.W.WW.WW...W..W.W....W.WW..WWW...WW..W...W........W..W.WWW..W......W.W..WW..WW...W......
output:
380858206
result:
ok single line: '380858206'
Test #13:
score: 6.25
Accepted
time: 59ms
memory: 8556kb
input:
2000 WW..WW..WW.WW.W...W....W...WWWW...W..W.W.W....W.W.W..W....W..W..W.W......W....WW...W..WW..W.........W.W....W..W.WW.WW......W..W.W....W..WW.WWW.WWW..WW..W.W.W.....WWW..WW..W.W...W.WW.W.W...W..........W...W..W....W...W....WW........W.W...WW..W..W...WW.WW....W.......W..WWW.W...W......WWW.WW..W..W....
output:
178610652
result:
ok single line: '178610652'
Test #14:
score: 6.25
Accepted
time: 61ms
memory: 8532kb
input:
2000 W...W..W...W.W.WW..WW....WW...W..WWW..W...W.WW.W......WW......WWW...W........WW.WWWW..W.....W.WW..W...W...WW..W...WW.W...W..WW......W.W.....W...W....W..W....W.W.W.....WW.....W.....WW...W.W.W.WW.W..W..W......W...WWW....WW...WWW..W.....W..W...WW....W.WW.W.W.W...W.W......W.....W..WWW.WW...WW..W..W...
output:
464018318
result:
ok single line: '464018318'
Test #15:
score: 6.25
Accepted
time: 58ms
memory: 8524kb
input:
2000 .WW.....W.W.......W...W.WWW.W..W..W.W.....W...WW.WW...W...WW..W.W.W...W.WWWW.W...W.W...WW.W.W..W...W.W.W...WWW..WW....W.W......WW.WWW....W..W.W.W.W.WW....WW....W..W...W..WW.....WWW.W...W.....W..WWWW.WW........W....W.....WWW...........WW......W.W..WW.W..WW..W.W..WW.WW.W.W.W....WW..W...WW.W..W.WW...
output:
751601279
result:
ok single line: '751601279'
Test #16:
score: 6.25
Accepted
time: 57ms
memory: 8640kb
input:
2000 .WW..WWWWW..W...W........WWWWW..W......W..WW.........WWWW....W.W.W.W..W.......W.WW..WW..WW..W.WW....W...W.WWW..W...W.....W.WW......W......W.WW.W..WWW.WWW....W....W.WW.............W.W.W...W.W......W....W.W.........W.WW....WW.......WW....W.W.W..W.W.W....W....WW.W.W.....W.........WW...W.....W.W......
output:
839346390
result:
ok single line: '839346390'