QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218489 | #7607. The Doubling Game 2 | ucup-team1209# | WA | 3ms | 20692kb | C++20 | 2.2kb | 2023-10-18 13:42:46 | 2023-10-18 13:42:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
typedef long long ll;
// #ifdef zqj
// #define sz 20
// #else
#define sz 303030
// #endif
const ll mod=int(1e9)+7;
int n;
vector<int>V[sz];
ll dp1[sz][21],dp2[sz][21],dp3[sz];
ll f1[1<<21],f2[1<<21],tmp1[1<<21],tmp2[1<<21];
int siz[sz];
void dfs(int x,int fa) {
siz[x]=1;
for (auto v:V[x]) if (v!=fa) {
dfs(v,x);
siz[x]+=siz[v];
}
sort(V[x].begin(),V[x].end(),[](int a,int b){return siz[a]<siz[b];});
int mx=2,_mx=2;
f1[0]=1;
for (auto v:V[x]) if (v!=fa) {
rep(s,0,(1<<mx)-1) tmp1[s]=f1[s],tmp2[s]=f2[s],f1[s]=f2[s]=0;
rep(s,0,(1<<mx)-1) {
rep(j,0,mx-1) if (dp1[v][j]) {
if (!(s>>j&1)) (f1[1<<j|s]+=tmp1[s]*dp1[v][j]%mod)%=mod;
if (!(s>>j&1)&&(1<<j)<s) (f2[1<<j|s]+=tmp2[s]*dp1[v][j]%mod)%=mod;
}
rep(j,0,mx-1) if (dp2[v][j]&&(1<<j)>s) {
(f2[1<<j|s]+=tmp1[s]*dp2[v][j]%mod)%=mod;
}
(f1[s]+=tmp1[s]*dp3[v]%mod)%=mod;
(f2[s]+=tmp2[s]*dp3[v]%mod)%=mod;
}
_mx=mx;
chkmax(mx,min(__lg(siz[v])+3,20));
}
mx=min(20,_mx+1);
rep(i,0,mx-1) dp1[x][i]=f1[(1<<i)-1];
rep(i,1,mx-1) rep(j,0,i-2) (dp2[x][j]+=f2[(1<<i)-1-(1<<j)])%=mod;
rep(i,1,mx-1) rep(j,0,i-1) (dp2[x][j]+=f1[(1<<i)-1-(1<<j)])%=mod;
// dp3[x]=f1[0];
rep(i,0,mx-1) (dp3[x]+=f1[(1<<i)-1]+(i?f2[(1<<i)-1]:0))%=mod;
rep(i,0,(1<<mx)-1) f1[i]=f2[i]=0;
// memset(f1,0,sizeof(f1)),memset(f2,0,sizeof(f2));
}
int main() {
// file();
ios::sync_with_stdio(false),cin.tie(0);
cin>>n;
int x,y;
rep(i,1,n-1) cin>>x>>y,V[x].push_back(y),V[y].push_back(x);
dfs(1,0);
cout<<dp3[1]<<'\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 17988kb
input:
5 1 2 1 3 1 4 4 5
output:
21
result:
ok single line: '21'
Test #2:
score: 0
Accepted
time: 0ms
memory: 16248kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 20692kb
input:
128 11 32 116 81 65 4 117 47 5 81 104 30 61 8 82 59 95 20 92 29 29 127 97 39 123 33 59 128 115 33 83 67 74 16 77 33 64 73 124 123 8 127 61 51 101 122 35 90 119 116 112 27 81 93 109 123 54 1 119 100 116 16 65 47 67 27 22 105 76 87 36 39 27 96 72 31 91 123 21 105 118 12 110 48 121 72 14 115 24 16 106 ...
output:
554054109
result:
wrong answer 1st lines differ - expected: '508800953', found: '554054109'