QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621700 | #8717. 骰子 | UESTC_OldEastWest | WA | 1013ms | 21968kb | C++17 | 1.9kb | 2024-10-08 16:20:51 | 2024-10-08 16:20:51 |
Judging History
answer
#include<cstdio>
#define ll long long
#define maxn 1505
#define maxm 405
using namespace std;
const ll mod=1e9+7;
int n,m,q;
ll b[maxn],p[maxn][maxm],d[maxm];
ll A[maxm][maxm];
struct matrix
{
int del;//偏移
ll p[maxm],q[maxm],val[maxm];
ll mul(ll x,ll y)
{
ll ret=1;
while(y)
{
if(y&1)
ret=ret*x%mod;
x=x*x%mod;
y>>=1;
}
return ret;
}
ll inv(ll x)
{
return mul(x,mod-2);
}
void inv()//上三角矩阵求逆
{
q[0]=inv(p[0]);
for(int i=1;i<=m;++i)
{
ll ret=0;
for(int j=0;j<i;++j)
ret=(ret+p[i-j]*q[j]%mod)%mod;
ret=(mod-ret)%mod;
q[i]=inv(ret);
}
for(int i=0;i<=m;++i)
for(int j=i;j<=m;++j)
A[i][j]=q[j-i];
}
void getval()
{
for(int i=0;i<=m;++i)
for(int j=0;j<=m;++j)
val[i]=(val[i]+A[i][j]*b[j]%mod)%mod;
}
}pre[maxn];
void getpre(ll a[],ll b[],ll c[])
{
for(int i=0;i<=m;++i)
c[i]=0;
for(int i=0;i<=m;++i)
for(int j=0;i+j<=m;++j)
c[i+j]=(c[i+j]+a[i]*b[j]%mod)%mod;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=0;i<=m;++i)
scanf("%lld",&b[i]);
for(int i=1;i<=n;++i)
{
for(int j=0;j<=m;++j)
{
scanf("%lld",&p[i][j]);
p[i][j]%=mod;
}
}
pre[0].p[0]=1;
pre[0].inv();
pre[0].getval();
for(int i=1;i<=n;++i)
{
pre[i].del=pre[i-1].del;
for(int j=0;j<=m;++j)
{
if(p[i][j]==0)
pre[i].del++;
else
{
for(int k=0;k<=m;++k)
d[k]=0;
for(int k=j;k<=m;++k)
d[k-j]=p[i][k];
break;
}
}
getpre(pre[i-1].p,d,pre[i].p);
pre[i].inv();
pre[i].getval();
}
for(int i=1;i<=q;++i)
{
int l,r;
scanf("%d%d",&l,&r);
ll ans=0;
int del=pre[r].del-pre[l-1].del;
for(int i=0;i+del<=m;++i)
ans=(ans+pre[r].p[i]*pre[l-1].val[i+del]%mod)%mod;
printf("%lld\n",ans);
}
return 0;
}
/*
3 3 3
4 3 2 1
0 1 0 1000000007
0 500000004 0 500000004
0 0 500000004 500000004
1 1
1 2
1 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5724kb
input:
3 3 3 4 3 2 1 0 1 0 1000000007 0 500000004 0 500000004 0 0 500000004 500000004 1 1 1 2 1 3
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
3 3 6 4 3 2 1 1000000007 0 1 0 1000000007 1 0 0 1000000007 0 1 0 1 1 1 2 1 3 2 2 2 3 3 3
output:
2 1 0 3 1 2
result:
ok 6 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5764kb
input:
1 1 1 604063100 57375033 742299910 257700098 1 1
output:
148903503
result:
ok 1 number(s): "148903503"
Test #4:
score: -100
Wrong Answer
time: 1013ms
memory: 21968kb
input:
1500 200 600000 253665324 876103781 804024983 929290295 908790466 176299158 528078340 696679927 416465140 509641654 705083449 361711737 250659645 735832780 35321360 383752049 203979021 178832532 785212637 514502839 169840231 65809146 504755349 516829442 382478309 901925498 142312128 782336477 741339...
output:
396460030 511961313 525565006 211723824 735320297 220019197 621570067 798644527 835478406 189858602 543951444 562387861 504654411 293681948 951201705 841236823 353764479 71491865 40322496 554098916 647642628 439202093 745093138 479566301 611020106 608055329 662015873 871420248 289991656 898693644 64...
result:
wrong answer 1st numbers differ - expected: '66394849', found: '396460030'