QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#481124#7613. Inverse Problemucup-team052TL 5ms4388kbC++233.0kb2024-07-16 20:35:232024-07-16 20:35:24

Judging History

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

  • [2024-07-16 20:35:24]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:4388kb
  • [2024-07-16 20:35:23]
  • 提交

answer

#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];
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=1;i<=n/2+2;i++)
	{
		for(int j=1;j<=i;j++)
		{
			int adw=dv[n-2][j];
			for(auto [w,v]:f[i-j])
			{
				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<=L&&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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 4388kb

input:

4
2
360
1
509949433

output:

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

result:

ok OK (4 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

9
185396120
468170792
837583517
696626231
338497514
762842660
800028852
928391161
733524004

output:


result: