QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533981 | #6132. Repair the Artwork | Tomato_Fish# | RE | 0ms | 3832kb | C++14 | 1.6kb | 2024-08-26 18:07:10 | 2024-08-26 18:07:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=110,M=110*110,mod=1e9+7;
int f[4*N][M],ID[N][N],a[N],sum;
int mi(int x,int t){
int d=1;
while(t){
if(t%2) d=(ll)d*x%mod;
x=(ll)x*x%mod;t/=2;
}
return d;
}
int ni(int x) {return mi(x,mod-2);}
int dfs(int l,int r){
if(ID[l][r]) return ID[l][r];
int mx=(r-l+1)*(r-l+2)/2,now=++sum;
for(int i=0;i<=mx;i++) f[now][i]=0;
if(l>r){
f[now][0]=1;
return now;
}
bool pd=true;
for(int i=l;i<=r;i++)
if(a[i]==1){
int lc=dfs(l,i-1),rc=dfs(i+1,r);
int mx1=(i-l)*(i-l+1)/2,mx2=(r-i)*(r-i+1)/2;
for(int j=0;j<=mx1;j++)
for(int k=0;k<=mx2;k++)
f[now][j+k]=(f[now][j+k]+(ll)f[lc][j]*f[rc][k])%mod;
pd=false;break;
}
if(!pd) return now;
for(int i=l;i<=r;i++)
if(a[i]==2){
int son=dfs(i+1,r);
int mx1=(i-l)*(i-l+1)/2,mx2=(r-i)*(r-i+1)/2;
for(int j=0;j<=mx2;j++)
f[now][mx1+j]=(f[now][mx1+j]-f[son][j]+mod)%mod;
}
f[now][mx]=(f[now][mx]+1)%mod;
return now;
}
int main()
{
int T;scanf("%d",&T);
while(T--){
int n,m;sum=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=0;i<=n+1;i++)
for(int j=0;j<=n+1;j++) ID[i][j]=0;
int rt=dfs(1,n),mx=n*(n+1)/2,Ans=0;
for(int i=1;i<=mx;i++) Ans=(Ans+(ll)f[rt][i]*mi(i,m))%mod;
printf("%d\n",Ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
input:
3 2 2 2 0 3 2 2 1 0 3 1 2 1 0
output:
8 3 1
result:
ok 3 number(s): "8 3 1"
Test #2:
score: -100
Runtime Error
input:
100 2 1 0 1 2 1 2 1 2 1 1 1 1 6 2 1 14 2 3 12 2 2 2 6 13 2 2 0 2 0 2 7 14 0 0 0 0 2 2 0 5 8 2 2 0 0 0 5 5 2 2 0 0 0 12 3 0 2 0 2 2 0 1 2 2 2 2 0 7 11 2 2 0 1 0 1 0 4 4 2 1 2 2 7 5 1 1 0 0 1 0 0 2 14 2 1 15 17 2 2 1 2 0 0 0 0 2 0 1 0 0 0 0 15 11 1 1 2 0 1 2 0 0 1 0 2 1 1 1 1 15 18 1 0 1 0 2 2 1 2 0 1...