QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#437433#8786. The Whole WorldKevin5307WA 0ms3768kbC++232.6kb2024-06-09 10:37:452024-06-09 10:37:46

Judging History

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

  • [2024-06-09 10:37:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-06-09 10:37:45]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll Mods[]={2,3,5,7,11,13,17,19,23,29};
const int Len=10;
int n,x[33];
ll y[33];
ll C[44][44];
class EquationSolver
{
	ll ksm(ll a,ll b,ll Mod)
	{
		ll ans=1;
		while(b)
		{
			if(b&1) ans=(longer)(ans)*a%Mod;
			b>>=1;
			a=(longer)(a)*a%Mod;
		}
		return ans;
	}
	public:
		bool solve(vector<vector<ll>> Mat,ll Mod)
		{
			int n=sz(Mat),m=sz(Mat[0])-1;
			int cur=0;
			for(int i=0;i<n;i++)
			{
				while(cur<m)
				{
					bool ok=false;
					for(int j=i;j<n;j++)
						if(Mat[j][cur])
							ok=true;
					if(ok) break;
					cur++;
				}
				if(cur==m) break;
				for(int j=i;j<n;j++)
					if(Mat[j][cur])
					{
						for(int k=0;k<=m;k++)
							swap(Mat[i][k],Mat[j][k]);
						break;
					}
				ll inv=ksm(Mat[i][cur],Mod-2,Mod);
				for(int k=0;k<=m;k++)
					Mat[i][k]=(longer)(Mat[i][k])*inv%Mod;
				for(int j=i+1;j<n;j++)
				{
					ll Val=Mat[j][cur];
					for(int k=0;k<=m;k++)
						Mat[j][k]=(Mat[j][k]-(longer)(Mat[i][k])*Val%Mod+Mod)%Mod;
				}
			}
			for(int i=0;i<n;i++)
			{
				bool ok=true;
				for(int j=0;j<m;j++)
					if(Mat[i][j])
						ok=false;
				if(!Mat[i][m])
					ok=false;
				if(ok)
					return false;
			}
			return true;
		}
}es;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=0;i<44;i++)
		C[i][i]=C[i][0]=1;
	for(int i=2;i<44;i++)
		for(int j=1;j<i;j++)
			C[i][j]=C[i-1][j]+C[i-1][j-1];
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>x[i]>>y[i];
		for(int d=0;;d++)
		{
			bool ok=true;
			for(int a=0;a<Len;a++)
			{
				vector<vector<ll>> Eq(n,vector<ll>(d+2));
				for(int i=1;i<=n;i++)
					for(int j=0;j<=d;j++)
						Eq[i-1][j]=C[x[i]][j]%Mods[a];
				for(int i=1;i<=n;i++)
					Eq[i-1][d+1]=(y[i]+Mods[a])%Mods[a];
				if(!es.solve(Eq,Mods[a]))
				{
					ok=false;
					break;
				}
			}
			if(ok)
			{
				cout<<d<<endl;
				break;
			}
		}	
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3768kb

input:

2
2
1 0
4 1
3
1 1
4 4
6 6

output:

3
1

result:

ok 2 number(s): "3 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3768kb

input:

2
2
1 0
4 1
3
1 0
3 0
5 4

output:

3
2

result:

wrong answer 2nd numbers differ - expected: '3', found: '2'