QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786498#8717. 骰子KanateRE 1ms3560kbC++172.0kb2024-11-26 21:49:372024-11-26 21:49:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 21:49:39]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3560kb
  • [2024-11-26 21:49:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7 ;
const int N = 1505;
const int M = 205;
int n , m , q;
ll t[N][205];
ll *r[N];
int cnt[N];
ll ans[205];
ll qpow(ll a,ll b){
    ll ans = 1;
    for(;b;b>>=1,a=a*a%mod) if(b&1) ans = ans * a %mod;
    return ans;
}

ll* inv(int n,ll *a){
    ll *b;
    b = (ll*)malloc(sizeof(ll)*M);
    memset(b,0,sizeof(ll)*M);
    ll inv = qpow(a[0],mod-2);
    b[0] = inv;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++) 
        b[i] = (b[i] - a[j]*b[i-j] + mod) % mod;
        b[i] = b[i] * inv % mod;
    }
    return b;
}

ll tmp[M],sum[N];

void mul(ll *a,ll *b){
    memset(tmp,0,sizeof tmp);
    for(int i=0;i<=200;i++)
    for(int j=0;j<=200-i;j++)
    tmp[i+j] = (tmp[i+j] + a[i] * b[j] %mod) % mod;
    for(int i=0;i<=200;i++) a[i] = tmp[i];
}
/*
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
*/
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> m >> q;
    t[0][0] = 1;
    for(int i=0;i<=m;i++) cin >> sum[i];
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m;j++) cin >> t[i][j];
        while(cnt[i]<=m){
            if((t[i][cnt[i]]%=mod)!=0) break;
            cnt[i]++;
        }
        for(int j=0;j<=m-cnt[i];j++)
        t[i][j] = t[i][j+cnt[i]];
        for(int j=m-cnt[j]+1;j<=m;j++)
        t[i][j] = 0 ;
        if(cnt[i] == m+1) t[i][0] = 1;
        if(i!=1){
            mul(t[i],t[i-1]);
            r[i] = inv(200,t[i]);
        }
        cnt[i] += cnt[i-1];
    }
    
    while(q-->0){
        int L,R ;
        cin >> L >> R;
        for(int i=0;i<=m;i++) ans[i] = t[R][i];
        int k = cnt[R] - cnt[L-1];
        if(L!=1) mul(ans,r[L-1]);
        ll ANS = 0 ;
        for(int i=k;i<=m;i++)
        ANS =(ANS + ans[i-k] * sum[i] %mod) %mod;
        cout << ANS << endl;
        
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3560kb

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: -100
Runtime Error

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

result: