QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189505 | #6132. Repair the Artwork | 275307894a | AC ✓ | 515ms | 8304kb | C++14 | 1.3kb | 2023-09-27 16:07:06 | 2023-09-27 16:07:08 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=100+5,M=N*20+5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
int n,m,A[N];ll dp[N][N*N/2];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
void Solve(){
int i,j,h;scanf("%d%d",&n,&m);
for(i=1;i<=n;i++) scanf("%d",&A[i]);
A[0]=A[n+1]=1;for(i=0;i<=n+1;i++) Me(dp[i],0);dp[0][0]=1;
for(i=1;i<=n+1;i++) {
if(!A[i]) continue;
for(j=i-1;~j;j--) {
for(h=0;h<=j*(j-1)/2;h++) if(dp[j][h]) dp[i][h+(i-j-1)*(i-j)/2]+=dp[j][h]*(A[i]^1?-1:1);
if(A[j]==1) break;
}
for(h=0;h<=i*(i-1)/2;h++) dp[i][h]%=mod;
}
ll ans=0;for(i=0;i<=n*(n+1)/2;i++) ans+=dp[n+1][i]*mpow(i,m)%mod;
printf("%lld\n",(ans%mod+mod)%mod);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4140kb
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: 0
Accepted
time: 0ms
memory: 6992kb
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...
output:
1 1 0 1 1 175715347 833406719 467966815 458805426 650344 2208 537089254 146 7776 1 703335050 123067364 355668256 487954758 53774922 544070885 436748805 369291507 760487845 513270785 501075264 487417783 464534262 979007529 137956839 143317512 648268264 851188473 702545117 946416372 595191705 35054850...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 216ms
memory: 8300kb
input:
1000 20 673037423 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 774964932 2 2 2 17 730319736 2 2 1 1 2 2 2 2 2 2 2 2 2 1 2 2 1 11 893285699 2 2 2 1 2 1 2 2 2 1 2 16 98149251 1 2 1 2 1 2 1 1 2 1 2 2 2 2 1 2 7 556953277 1 2 2 1 2 2 2 3 228111342 1 1 1 11 640995044 2 2 1 1 2 2 1 1 1 1 1 19 741419324 1 1 2 ...
output:
447486147 204414804 452414918 684654914 763978130 805973365 0 922180033 214948715 401017738 0 201368027 752718484 611006275 848004989 391560729 950934074 202096866 443534870 24665646 482580424 321199514 922369975 152629767 5546104 1 194145234 1 1 1 562381239 648246425 497517379 217016206 961507095 4...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 515ms
memory: 8304kb
input:
1000 50 416236992 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 50 657728991 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 50 740461763 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
763259804 476502422 599342821 232859927 793988697 591429049 270188459 585052379 112828376 874793236 511742305 443789116 531138043 829814299 715762187 530976897 659595243 398499036 665696512 377388317 780011237 877457048 769085674 80046792 628967449 305823394 274620920 654337446 807171478 690217437 6...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 281ms
memory: 8208kb
input:
1000 50 598094879 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 50 370102582 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 50 89148477 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
799398716 932856936 764416567 57812598 711885564 231337579 355184372 128337468 66039637 243697360 95147120 522827313 427687773 11613749 119992325 840421248 552748897 2153604 854978507 598264350 888588637 168914307 64499881 640494492 442303426 759524304 392240094 936658374 641034548 250860728 8449099...
result:
ok 1000 numbers