QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779482#9254. Random Variablesbyron10000RE 0ms10956kbC++141.9kb2024-11-24 19:21:312024-11-24 19:21:31

Judging History

This is the latest submission verdict.

  • [2024-11-24 19:21:31]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 10956kb
  • [2024-11-24 19:21:31]
  • Submitted

answer

#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
typedef pair<int,int> pii;
typedef __int128 i128;
namespace std{
    template<>
    struct hash<pair<int,int>>{
        size_t operator()(const pair<int,int>& x)const{ return _Hash_bytes(&x,sizeof(x),0xc70f6907); }
    };
}
const int MAXN=1010; const long NINF=0xc0c0c0c0c0c0c0c0;
int mod,fac[MAXN],inv[MAXN],n,m;
long C[MAXN][MAXN];
unordered_map<pair<int,int>,long> mp;
long dfs(int i,int j,int k){
    if(i==0) return 1;
    if(i<0||j<=0||1l*j*k<i) return 0;
    if(auto it=mp.find({i,j}); it!=mp.end()) return it->se;
    auto ret=j*(dfs(i-1,j,k)-dfs(i-1-k,j-1,k)*C[i-1][k])%mod;
    assert(ret>=0);
    return mp[{i,j}]=ret;
}
long solve(int k){
    if(k==0) return 0;
    mp.clear();
    return dfs(n,m,k);
}
void case_main(){
    cin>>n>>m;
    long ans=0,sum=1;
    RNG(_,1,n) sum=sum*m%mod;
    IRNG(k,n,1){
        auto x=solve(k-1);
        ans=(ans+(sum-x+mod)*k)%mod;
        sum=x;
    }
    cout<<ans<<"\n";
}
int main(){
#if defined(_LOCAL_)
    freopen("in","r",stdin);
//  freopen("out","w",stdout);
//  freopen("/dev/null","w",stderr);
#else
//  freopen("yesterday.in","r",stdin);
//  freopen("yesterday.out","w",stdout);
#endif
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int cas; cin>>cas>>mod;
    auto N=1000;
    C[0][0]=1;
    RNG(i,1,N){
        C[i][0]=1;
        RNG(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
    RNG(_,1,cas) case_main();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10956kb

input:

3 123456789
3 2
5 5
7 7

output:

18
7145
2066323

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 10912kb

input:

100 2
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
8 1
8 2...

output:

1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 lines

Test #3:

score: -100
Runtime Error

input:

100 3
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
8 1
8 2...

output:


result: