QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#481594 | #7613. Inverse Problem | ucup-team052 | WA | 4844ms | 19900kb | C++23 | 3.4kb | 2024-07-17 10:51:20 | 2024-07-17 10:51:20 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int md = 1e9 + 7;
const int mod = 1e9 + 7;
inline int add(int x, int y) {
if (x + y >= md) return x + y - md;
return x + y;
}
inline int sub(int x, int y) {
if (x < y) return x - y + md;
return x - y;
}
inline int mul(int x, int y) {
return 1ull * x * y % md;
}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
inline int qpow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
}
int Inv(int x) {return qpow(x,mod-2);}
const int L=200;
int n,dv[L+5][L+5],idv[L+5][L+5];
unordered_map<int,int> f[L+1];
/*
void init()
{
for(int i=0;i<=n;i++) f[i].clear();
f[0][1]=1;
for(int i=0;i<=n/2+2;i++)
{
for(auto [w,v]:f[i])
{
for(int j=v;i+j<=n/2+2;j++)
{
int gw=mul(dv[n-2][j],w);
if(f[i+j].find(gw)==f[i+j].end()) f[i+j][gw]=j;
else f[i+j][gw]=min(f[i+j][gw],j);
}
}
}
}
*/
void init()
{
for(int i=0;i<=n;i++) f[i].clear();
f[0][1]=1;
for(int i=1;i<=n/2;i++)
{
for(int j=1;j<=i;j++)
{
int adw=dv[n-2][j];
for(auto [w,v]:f[i-j])
{
if(j<v) continue;
int gw=mul(adw,w);
if(f[i].find(gw)==f[i].end())
{
f[i][gw]=j;
}
}
}
}
}
int Q,q[15],ok[15],sok;
vector<int> ans[15];
int ansn[15];
vector<int> getvec(int s,int w)
{
vector<int> ans;
while(s)
{
int j=f[s][w];
w=mul(w,idv[n-2][j]);
ans.push_back(j);
s-=j;
}
return ans;
}
int main() {
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
for(int i=1;i<=L;i++)
{
dv[i][0]=1;
for(int j=1;j<=L;j++) dv[i][j]=mul(dv[i][j-1],i-j+1),idv[i][j]=Inv(dv[i][j]);
}
cin>>Q;
for(int i=1;i<=Q;i++)
{
cin>>q[i];
if(q[i]==1) ok[i]=1,sok++;
if(q[i]==2)
{
ok[i]=1,sok++;
}
}
for(n=3;n<=125&&sok<Q;n++)
{
fprintf(stderr,"n = %d\n",n);
init();
int adw=mul(n,n-1);
for(int qid=1;qid<=Q;qid++)
{
// q[qid] sum=n-2
for(int big=1;big<=n-2&&!ok[qid];big++)
{
int cw=dv[n-2][big];
for(int L=0;L<=big&&!ok[qid];L++)
{
int R=n-2-big-L;
// printf("%d %d %d\n",big,L,R);
if(!(R>=0)) continue;
for(auto [w,v]:f[L])
{
int way=mul(adw,w,cw);
int ned=mul(Inv(way),q[qid]);
if(f[R].find(ned)!=f[R].end())
{
vector<int> vl=getvec(L,w);
vector<int> vr=getvec(R,ned);
ans[qid]=vl;
for(int t:vr) ans[qid].push_back(t);
ans[qid].push_back(big);
ok[qid]=1;
ansn[qid]=n;
sok++;
break;
}
}
}
}
}
}
for(int i=1;i<=Q;i++)
{
if(q[i]==1) printf("1\n");
else if(q[i]==2) printf("2\n1 2\n");
else
{
printf("%d\n",ansn[i]);
while(ans[i].size()<ansn[i]) ans[i].push_back(0);
// for(int j=0;j<(int)ans[i].size();j++) ans[i][j]++;
for(int j=0;j<ansn[i]-1;j++)
{
for(int c=0;c<(int)ans[i].size();c++) for(int d=0;d<(int)ans[i].size();d++)
{
if(ans[i][c]==0&&ans[i][d]>0)
{
ans[i][c]--,ans[i][d]--;
printf("%d %d\n",c+1,d+1);
}
}
}
for(int c=0;c<(int)ans[i].size();c++) for(int d=c+1;d<(int)ans[i].size();d++)
{
if(ans[i][c]==0&&ans[i][d]==0)
{
ans[i][c]--,ans[i][d]--;
printf("%d %d\n",c+1,d+1);
}
}
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 4844ms
memory: 19900kb
input:
4 2 360 1 509949433
output:
2 1 2 5 3 1 4 1 5 2 1 2 1 87 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 2 34 2 35 3 36 3 37 4 38 4 39 5 40 5 41 6 42 6 43 6 44 6 45 6 46 6 47 6 48 6 49 7 50 7 51 7 52 7 53 7 54 7 55 7 56 8 57 8 58 8 59 8 60 8 61 8 62 9 63 9 64 9 65 9 66 10 67 10 68 10 69 11 70 11 71 12 72 12...
result:
wrong answer Jury znalazło mniejsze drzewo! (test case 4)