QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620704 | #4514. Schrödinger and Pavlov | SAMWer | 50 ✓ | 379ms | 3988kb | C++14 | 1.7kb | 2024-10-07 20:33:26 | 2024-10-07 20:33:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define il inline
#define vd void
#define bl bool
#define fr(x) freopen(#x".in","s",stdin);freopen(#x".out","w",stdout)
using namespace std;
const ll N=5e3+2,P=1e9+7;
struct zjy{char c;ll b,f;bl bz;}a[N];
il ll R()
{
ll n=0,f=1;
char c;
for(c=getchar();c!='-'&&(c<'0'||c>'9');c=getchar());
if(c=='-') f=-1,c=getchar();
for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-'0';
return n*f;
}
il vd W(ll x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) W(x/10);
putchar(x%10+'0');
}
signed main()
{
ll n,i,ans,T,mn,z,s,tt;
for(T=R(),tt=1;tt<=T;++tt)
{
for(n=R(),i=1;i<=n;++i) scanf("%c",&a[i].c);
for(i=1;i<=n;++i) a[i].b=R();
vector<ll> c(1,n);
while(a[c.back()].bz=1,!a[a[c.back()].b].bz) c.push_back(a[c.back()].b);
for(ll x:c) a[x].bz=0;
c.erase(c.begin(),find(c.begin(),c.end(),a[c.back()].b));
mn=N;
for(ll x:c) mn=min(mn,x);
a[mn].bz=1;
for(ll x:{0,1})
{
for(ll y:{0,1})
{
for(i=1;i<=n;++i) a[i].f=a[i].c=='?'?P+1>>1:a[i].c=='C';
for(s=i=1;i<=n;++i)
{
ll &p=a[i].f,&q=a[a[i].b].f;
if(a[i].bz)
{
s=s*(x?p:1-p+P)%P*(y?q:1-q+P)%P;
p=x&&y,q=x||y;
}
else z=p,p=p*q%P,q=(z+q-z*q%P+P)%P;
}
ans=(ans+s*a[n].f)%P;
}
}
for(i=1;i<=n;++i) ans=ans*(a[i].c=='?'?2:1)%P;
cout<<"Case #"<<tt<<": ";
W(ans);
putchar('\n');
memset(a,0,sizeof(a));
ans=0;
}
}
詳細信息
Pretests
Final Tests
Test #1:
score: 8
Accepted
time: 11ms
memory: 3884kb
input:
1234 92 ???????????????????????????????????????????????????????????????????????????????????????????? 2 1 2 3 4 7 5 7 8 9 15 9 15 12 14 15 16 19 16 17 17 20 22 23 24 25 26 27 28 29 30 31 32 33 34 38 34 39 35 39 45 40 42 43 44 45 46 47 48 49 50 51 52 57 53 55 56 56 57 59 60 61 62 63 64 64 66 67 68 69 ...
output:
Case #1: 75340207 Case #2: 248320570 Case #3: 1 Case #4: 501005577 Case #5: 0 Case #6: 0 Case #7: 0 Case #8: 988185614 Case #9: 0 Case #10: 840220993 Case #11: 140130951 Case #12: 8 Case #13: 0 Case #14: 0 Case #15: 570065479 Case #16: 128 Case #17: 67108864 Case #18: 0 Case #19: 0 Case #20: 5605238...
result:
ok 1234 lines
Test #2:
score: 42
Accepted
time: 379ms
memory: 3988kb
input:
1234 4693 ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
Case #1: 13595505 Case #2: 0 Case #3: 370024028 Case #4: 332957307 Case #5: 0 Case #6: 401898087 Case #7: 588719939 Case #8: 0 Case #9: 0 Case #10: 0 Case #11: 893344250 Case #12: 816205426 Case #13: 902710840 Case #14: 735342227 Case #15: 0 Case #16: 623834768 Case #17: 195615577 Case #18: 44692699...
result:
ok 1234 lines