QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232355 | #1811. How to Move the Beans | AFewSuns | WA | 4ms | 7848kb | C++14 | 2.8kb | 2023-10-30 11:32:01 | 2023-10-30 11:32:01 |
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;
#define L(x) (((x)+m-2)%m+1)
#define R(x) ((x)%m+1)
ll n,m,f[1010][1010],l[1010],r[1010],lto[1010][4],rto[1010][4],lft[1010][4],rgt[1010][4];
char s[1010][1010];
il ll calc(ll a1=-1,ll a2=-1,ll a3=-1){
fr(i,0,3) if(i!=a1&&i!=a2&&i!=a3) return i;
}
int main(){
n=read();
m=read();
fr(i,1,n) scanf("%s",s[i]+1);
fr(i,1,m) f[n+1][i]=-1;
pfr(i,n,1){
ll pos=0;
fr(j,1,m) if(s[i][j]=='#') pos=j;
if(pos){
fr(j,0,m-1){
ll now=(pos+j-1)%m+1;
if(s[i][now]=='#') l[now]=-1;
else l[now]=calc(l[L(now)],f[i+1][now]);
}
pfr(j,m,1){
ll now=(pos+j-1)%m+1;
if(s[i][now]=='#') r[now]=-1;
else r[now]=calc(r[R(now)],f[i+1][now]);
}
fr(j,1,m) f[i][j]=calc(l[L(j)],r[R(j)]);
}
else if(m==1) f[i][1]=calc(f[i+1][1]);
else{
fr(j,0,3) lto[1][j]=rto[m][j]=lft[1][j]=rgt[m][j]=j;
fr(j,2,m) fr(k,0,3) lto[j][k]=lto[j-1][calc(k,f[i+1][j-1])];
pfr(j,m-1,1) fr(k,0,3) rto[j][k]=rto[j+1][calc(k,f[i+1][j+1])];
fr(j,2,m) fr(k,0,3) lft[j][k]=calc(lft[j-1][k],f[i+1][j]);
pfr(j,m-1,1) fr(k,0,3) rgt[j][k]=calc(rgt[j+1][k],f[i+1][j]);
fr(j,1,m){
ll tmp1,tmp2;
if(j==1) tmp1=rto[j+1][calc(f[i+1][j+1])];
else tmp1=lft[j-1][calc(rto[j+1][calc(f[i+1][j+1])],f[i+1][1])];
if(j==m) tmp2=lto[j-1][calc(f[i+1][j-1])];
else tmp2=rgt[j+1][calc(lto[j-1][calc(f[i+1][j-1])],f[i+1][m])];
f[i][j]=calc(tmp1,tmp2,f[i+1][j]);
}
}
fr(j,1,m) if(s[i][j]=='#') f[i][j]=-1;
}
ll ans=0;
fr(i,1,n) fr(j,1,m) if(s[i][j]=='B') ans^=f[i][j];
if(ans) pf("Alice");
else pf("Bob");
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 7848kb
input:
293 249 #B..B..BBB..B.B.B...#BBB..B#B.BBB.#B##B.BB.B.##B#B.BB..B.#B#BB.BB##B#BB#...B..BB..B.B##B.B#B.#.##..B.#..BBBB#.BB..#.BBB#B##BB....B.##B..#...B#..B.BB#B.#...B#.BB.#B#.B...BBB.B.B..B....##.B..B##.BB#B.B.BBB.B#B..#.B.B#.B##..B#.##BB.#BB#.BB.#.B..BB.BB.B BB.B.#.B#BB.B.B..B.###.B...BB.##.B...B#BB....
output:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'