QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#447309 | #6954. Almost Acyclic | Acoipp | WA | 1290ms | 151512kb | C++14 | 2.5kb | 2024-06-18 09:28:19 | 2024-06-18 09:28:20 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll T,n,i,j,val[17][17],a[17][17],tr,cir[17],ans1,ans2,ans,f[1<<17][17][17],id[17];
inline ll calc(ll x){return x*(x-1)/2;}
inline ll qmi(ll a,ll b,ll p){
ll res = 1%p,t = a;
while(b){
if(b&1) res=res*t%p;
t=t*t%p;
b>>=1;
}
return res;
}
inline ll solve_tree(ll n){
ll has=0,i,j,k,ans=1,res;
for(i=1;i<n;i++) for(j=1;j<n;j++) a[i][j]=(a[i][j]%mod+mod)%mod;
for(i=1;i<n;i++){
for(j=i+1;j<n;j++){
while(a[i][i]){
res = a[j][i]/a[i][i];
for(k=i;k<n;k++) a[j][k]=(a[j][k]-a[i][k]*res%mod+mod)%mod;
swap(a[i],a[j]),has^=1;
}
swap(a[i],a[j]),has^=1;
}
}
if(i<n){
cout<<0<<endl;
return 0;
}
for(i=1;i<n;i++) ans=ans*a[i][i]%mod;
if(has) ans=(mod-ans)%mod;
return ans;
}
inline ll solve_ans1(){
ll ans = 0;
return ans;
}
inline ll solve_ans2(){
ll ans = 0;
return ans;
}
inline void solve_cir(){
for(ll i=1;i<=n;i++) for(ll j=1;j<=n;j++) for(ll k=0;k<(1<<n);k++) f[k][i][j]=0;
for(ll i=1;i<=n;i++) f[1<<i-1][i][i]=1;
for(ll i=1;i<(1<<n);i++){
ll res = 0,cnt = __builtin_popcount(i),tot = 0;
if(cnt<=2) goto end;
for(ll j=0;j<n;j++){
for(ll k=0;k<n;k++){
if(j!=k&&((i>>j)&1)&&((i>>k)&1)) res=(res+f[i][j+1][k+1]*val[j+1][k+1])%mod;
}
}
res = res*qmi(2*cnt,mod-2,mod)%mod;
memset(a,0,sizeof(a));
for(ll j=0;j<n;j++){
if(!((i>>j)&1)) id[j+1]=++tot;
else id[j+1]=n-cnt+1;
}
for(ll j=1;j<=n;j++){
for(ll k=j+1;k<=n;k++){
a[id[j]][id[k]]-=val[j][k];
a[id[k]][id[j]]-=val[j][k];
a[id[j]][id[j]]+=val[j][k];
a[id[k]][id[k]]+=val[j][k];
}
}
cir[cnt] = (cir[cnt]+res*solve_tree(n-cnt+1));
end:;
for(ll j=0;j<n;j++) for(ll k=0;k<n;k++) for(ll l=0;l<n;l++) if(!((i>>l)&1)&&((i>>j)&1)&&((i>>k)&1)) f[i|(1<<l)][j+1][l+1]=(f[i|(1<<l)][j+1][l+1]+f[i][j+1][k+1]*val[k+1][l+1])%mod;
}
}
int main(){
ios::sync_with_stdio(false);
cin>>T;
while(T--){
memset(cir,0,sizeof(cir));
memset(a,0,sizeof(a));
cin>>n;
for(i=1;i<=n;i++) for(j=1;j<=n;j++) cin>>val[i][j];
for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) a[i][i]+=val[i][j],a[j][j]+=val[i][j],a[i][j]-=val[i][j],a[j][i]-=val[i][j];
tr = solve_tree(n);
ans1 = solve_ans1();
ans2 = solve_ans2();
solve_cir();
ans = ans1-ans2+tr*(calc(n)-n+1)%mod;
for(i=1;i<=n;i++) ans+=cir[i]*(calc(i)-i+1)%mod,cout<<cir[i]<<" ";
cout<<endl;
cout<<(ans%mod+mod)%mod<<endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1290ms
memory: 151512kb
input:
16 1 0 2 0 953763239 953763239 0 3 0 734999893 771971068 734999893 0 980773372 771971068 980773372 0 4 0 295218414 142837698 715328025 295218414 0 833169030 224028769 142837698 833169030 0 450275651 715328025 224028769 450275651 0 5 0 168127828 27116722 242318695 817220009 168127828 0 719973784 3288...
output:
0 0 0 0 0 0 0 871535383 858912196 0 0 523936023957082496 105219967 58858760 0 0 1069360857455277774 557009166943786436 913914568 279123107 0 0 5320472917676962610 3400024891956843380 2663929729985356041 752929126 490818994 0 0 7195808228463461017 8897011374641802594 4698805290248406034 1111098...
result:
wrong answer 1st lines differ - expected: '1', found: '0 '