QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#224746#7613. Inverse ProblemCrysflyAC ✓15386ms887336kbC++174.7kb2023-10-23 13:10:522023-10-23 13:10:53

Judging History

你现在查看的是最新测评结果

  • [2023-10-23 13:10:53]
  • 评测
  • 测评结果:AC
  • 用时:15386ms
  • 内存:887336kb
  • [2023-10-23 13:10:52]
  • 提交

answer

/*
modified b Crysfly

dfs 时 vector 放在外面
用数组代替 vector
O(n) 预处理逆元(重要)
加了点剪枝(重要)
*/
const int mv=62;
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <stdio.h>
#include <array>
#include <random>
//#include <bits/extc++.h>
#include <queue>	
std::mt19937_64 rng(0x3d03d);
#include <math.h>
#include <time.h>
#include <assert.h>
#include <bitset>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
using std::pair;
#include <vector>
#include <bitset>
#include <set>
#define ld(x) printf("%lld\n",x)

typedef unsigned short ui;

//#define int long long
#define ll long long
const int mod=1e9+7;
using std::vector;
using vi=vector<short>;
using pi=std::pair<int,int>;
using vpi=vector<pi>;
#define x first
#define y second
inline int min(int a,int b){return a>b?b:a;}
inline int max(int a,int b){return a<b?b:a;}
inline int read()
{
    int num=0,f=1;char c=getchar();
    while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
    while(c>47&&c<58)num=num*10+(c^48),c=getchar();
    return num*f;
}
int w[160];

std::bitset<mod>bs;

vi P[10000006];
vi Now;
int ptot;
int L[66],R[66];
inline int qp(int a,int b){int c=1;while(b){if(b&1)c=1ll*c*a%mod;a=1ll*a*a%mod;b>>=1;}return c;}
inline int ve(int a,int b){return 1ll*a*qp(b,mod-2)%mod;}
void dfs(int u,int mx,int s)
{
	if(u==0)
	{
		P[++ptot]=Now;
		assert(ptot<=1e7);
		return;
	}
	for(int j=mx;j<=u;j++) if(j==u||u-j>=j)
	{
		Now.push_back(j);
		dfs(u-j,j,s);
		Now.pop_back();
	}
}
int Q[11],N[11];vi Rec[11];
int iw[999];

int nd[10000007],ind[10000007],mul[10000007],imul[10000007],tot;
void init(int tot){
	mul[0]=1;
	For(i,1,tot) mul[i]=1ll*mul[i-1]*nd[i]%mod;
	imul[tot]=qp(mul[tot],mod-2);
	Rep(i,tot-1,0) imul[i]=1ll*imul[i+1]*nd[i+1]%mod,ind[i+1]=1ll*imul[i+1]*mul[i]%mod;
}
//vector<int> vec[66];

signed main()
{
	int T=read(),ww=T;
	for(int i=0;i<=mv;i++) L[i]=ptot+1,dfs(i,1,i),R[i]=ptot;
	// return 0;
	for(int i=1;i<=T;i++)
	{
		Q[i]=read();
		if(Q[i]<=2)N[i]=Q[i],ww--;
	}
//	puts("qwq");
	
//	puts("QAQ");
	{
		// int r=read();
		for(int n=1;n<=mv*2 && ww;n++)
		{
			std::cerr<<"work "<<n<<"\n";
			//(n+1)(n+2)
			tot=0;
			int d=ve(1,(n+1)*(n+2));
			w[n]=n;w[n+1]=1;
			for(int i=n-1;i>=1;i--)w[i]=1ll*w[i+1]*i%mod;
			for(int i=1;i<=n+1;i++)iw[i]=qp(w[i],mod-2);

			for(int i=0;i<=n/2;i++)
			{
		//		for(int j=0;j<P[i].size();++j)
				For(j,L[i],R[i])
		//		for(vi &t:P[i])
				{
					vi&t=P[j];
					int ws=1;
					for(int a:t)ws=1ll*ws*w[n-a+1]%mod;
					// for(int a:t)printf("%d ",a);printf("(%d %d)\n",n,ws);
					// z[i][ws]=t;
				//	++tot;
					nd[j]=ws;
				//	vec[i][j]=tot;
				//	vec[i].push_back({tot,t});
				}
			}
			init(R[n/2]);
			std::cerr<<"N: "<<n<<"\n";
			// continue;
			// 1 1 1 1 1 1 1 1
			// printf("!!!!!!!!!!!!!!!r%d\n",r);
			for(int j=0;j<=n/2;j++)
			{		
				For(x,L[j],R[j])
				{
					// printf("%d : %d , %d\n",n,j,x);fflush(stdout);
					bs.set(nd[x]);
				}
						// continue;
				for(int i=0;i<=j;i++)
			// for(int S=0;S<=n;S++)
				// int tmp=qp(w[S+1],mod-2)*d%mod;
				// assert(tmp);
				// for(int i=0,j=S;j>=0;i++,j--)
				{
				//	for(auto &wi:vec[i])
					int ss=1ll*d*iw[i+j+1]%mod;
				//	for(int ii=0;ii<vec[i].size();++ii)
					For(ii,L[i],R[i])
					if(i==0||P[ii][0]>=n-i-j)
					{
						int sj=1ll*ss*ind[ii]%mod;
						for(int q=1;q<=T;q++)if(!N[q])
						{
							int wj=1ll*sj*Q[q]%mod;
							if(bs.test(wj))
							{
								vi res;
								bool ok=0;
							//	for(int k=0;k<vec[j].size();++k)
								For(k,L[j],R[j])
									if(nd[k]==wj){
										res=P[k];
										ok=1;
										break;
									}
								assert(ok);
							//	for(auto x:vec[j])if(nd[x]==wj)res=y;
								for(int t:P[ii])res.push_back(t);
								res.push_back(n-i-j);
								std::sort(res.begin(),res.end());
								N[q]=n+2;
								Rec[q]=res;
								ww--;
							}
						}
					}
				//	else break;
				}
				For(x,L[j],R[j])
				{
					// printf("%d : %d , %d\n",n,j,x);fflush(stdout);
					bs.reset(nd[x]);
				}
			}
		}
		// 😎:;
	}
	for(int i=1;i<=T;i++)
	{
		int n=N[i];vi res=Rec[i];
		if(n==0)
			puts("暂时不能给你明确的答复!");
		if(n==1)puts("1");
		if(n==2)puts("2\n1 2");
		if(n<=2)continue;
		ld(n);
		n-=2;
		// continue;
		puts("1 2");
		int nw=2;
		for(int i=1;i<=res.size();i++)
			while(res[i-1]--)printf("%d %d\n",i,++nw);
	}

	fprintf(stderr,"%.12lf\n",1.*clock()/CLOCKS_PER_SEC);
	return 0;
}
/*
1
468170792
*/

詳細信息

Test #1:

score: 100
Accepted
time: 335ms
memory: 642928kb

input:

4
2
360
1
509949433

output:

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

result:

ok OK (4 test cases)

Test #2:

score: 0
Accepted
time: 13208ms
memory: 887300kb

input:

9
185396120
468170792
837583517
696626231
338497514
762842660
800028852
928391161
733524004

output:

14
1 2
1 3
2 4
3 5
4 6
5 7
6 8
7 9
8 10
9 11
9 12
10 13
10 14
122
1 2
1 3
2 4
3 5
4 6
5 7
6 8
6 9
7 10
7 11
8 12
8 13
9 14
9 15
9 16
10 17
10 18
10 19
11 20
11 21
11 22
12 23
12 24
12 25
12 26
13 27
13 28
13 29
13 30
14 31
14 32
14 33
14 34
14 35
15 36
15 37
15 38
15 39
15 40
15 41
15 42
16 43
16 44...

result:

ok OK (9 test cases)

Test #3:

score: 0
Accepted
time: 15386ms
memory: 887336kb

input:

10
338497514
733524004
447182954
415993605
453460670
50499055
648088551
986982752
907925397
315315230

output:

124
1 2
1 3
1 4
1 5
2 6
2 7
2 8
3 9
3 10
3 11
3 12
4 13
4 14
4 15
4 16
5 17
5 18
5 19
5 20
6 21
6 22
6 23
6 24
7 25
7 26
7 27
7 28
8 29
8 30
8 31
8 32
9 33
9 34
9 35
9 36
9 37
9 38
10 39
10 40
10 41
10 42
10 43
10 44
10 45
10 46
11 47
11 48
11 49
11 50
11 51
11 52
11 53
11 54
11 55
11 56
11 57
12 58...

result:

ok OK (10 test cases)

Test #4:

score: 0
Accepted
time: 2727ms
memory: 788924kb

input:

10
1
2
3
4
5
6
7
8
9
10

output:

1
2
1 2
102
1 2
1 3
2 4
3 5
4 6
4 7
5 8
5 9
6 10
6 11
7 12
7 13
8 14
8 15
9 16
9 17
9 18
9 19
9 20
9 21
10 22
10 23
10 24
10 25
10 26
10 27
10 28
10 29
11 30
11 31
11 32
11 33
11 34
11 35
11 36
11 37
11 38
12 39
12 40
12 41
12 42
12 43
12 44
12 45
12 46
12 47
12 48
13 49
13 50
13 51
13 52
13 53
13 5...

result:

ok OK (10 test cases)

Test #5:

score: 0
Accepted
time: 1002ms
memory: 772540kb

input:

10
269199917
392009324
753889928
751355133
472639410
132096559
331333826
40414701
72847302
475706026

output:

55
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 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
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
84
1 2
1 3
2 4
3 5
4 6
5 7
6 8
7 9
...

result:

ok OK (10 test cases)

Extra Test:

score: 0
Extra Test Passed