QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#437459 | #8786. The Whole World | Kevin5307 | TL | 7740ms | 3856kb | C++23 | 2.7kb | 2024-06-09 10:59:19 | 2024-06-09 10:59:20 |
Judging History
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,31,37,41,43,47,53,59};
const int Len=17;
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,ll r)
{
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]%r)
ok=true;
if(ok) break;
cur++;
}
if(cur==m) break;
for(int j=i;j<n;j++)
if(Mat[j][cur]%r)
{
for(int k=0;k<=m;k++)
swap(Mat[i][k],Mat[j][k]);
break;
}
ll inv=ksm(Mat[i][cur],(Mod-Mod/r)*2-1,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));
ll realMod=Mods[a];
while(realMod<=1e16)
{
for(int i=1;i<=n;i++)
for(int j=0;j<=d;j++)
Eq[i-1][j]=C[x[i]][j]%realMod;
for(int i=1;i<=n;i++)
Eq[i-1][d+1]=(y[i]+realMod)%realMod;
if(!es.solve(Eq,realMod,Mods[a]))
{
ok=false;
break;
}
realMod*=Mods[a];
}
}
if(ok)
{
cout<<d<<endl;
break;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
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: 0
Accepted
time: 1ms
memory: 3768kb
input:
2 2 1 0 4 1 3 1 0 3 0 5 4
output:
3 3
result:
ok 2 number(s): "3 3"
Test #3:
score: 0
Accepted
time: 10ms
memory: 3648kb
input:
2 10 1 557 2 -172 3 -497 5 763 6 -149 7 -355 8 -29 9 -588 10 -171 11 -355 10 1 -461 2 -219 3 -45 4 -212 5 749 6 -294 9 -85 10 213 11 -412 12 125
output:
10 11
result:
ok 2 number(s): "10 11"
Test #4:
score: 0
Accepted
time: 645ms
memory: 3856kb
input:
20 10 1 -193165761 4 426322868 5 -408198139 7 -455731045 9 -389028341 17 -590246653 18 119481348 21 809814532 23 47591392 26 -21020402 10 3 -715116939 5 -263142266 6 -426687860 10 342227448 14 141724722 15 576758779 18 123410194 19 256532828 20 -223524833 25 386574889 10 5 34943085 7 238431559 9 168...
output:
25 22 23 20 20 25 23 25 26 23 23 25 29 23 24 29 29 27 25 19
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 3071ms
memory: 3584kb
input:
100 10 1 158027281 3 -154375927 6 -515683907 9 -801063453 15 371607728 16 -30224647 24 -215349633 26 219182013 29 -87257968 30 186925822 10 2 205585983 9 740879281 11 -672242855 14 -53907640 16 146130715 20 -17941862 25 -424140108 26 593743162 27 -8310423 28 84863497 10 3 46810292 4 361101002 5 4687...
output:
29 25 25 20 19 25 20 29 29 19 25 19 26 26 27 21 27 26 25 25 24 26 27 25 25 27 26 23 27 23 29 25 27 26 28 29 29 20 21 23 22 25 23 16 25 29 26 25 26 18 23 18 23 19 28 19 26 26 24 18 26 19 23 27 21 23 17 26 28 25 27 23 16 19 25 26 23 25 14 23 20 20 25 23 24 23 19 19 20 20 22 26 26 25 22 23 28 17 19 19
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 4892ms
memory: 3612kb
input:
100 30 1 -519015304 2 269671593 3 -163533023 4 830108438 5 337806976 6 -87888761 7 -195233355 8 -341350273 9 38092088 10 285610643 11 -240058763 12 256373103 13 297741964 14 -247379404 15 -26410774 16 -755197562 17 -643221179 18 159031836 19 689848941 20 622207228 21 -407862690 22 401550934 23 10884...
output:
29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 6027ms
memory: 3564kb
input:
100 29 1 149105603 2 19193029 3 -254160491 4 -298710412 5 -329725675 6 644578442 7 611132722 8 -806708763 9 506813970 10 566271854 11 -621025393 12 293347092 13 -332652769 14 -320671582 15 507576094 16 -153368460 17 -242687628 18 545685752 19 -359086703 20 -31631637 21 34200734 22 695203819 23 66205...
output:
29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 28 29 29 29 29 28 29 29 29 29 29 29 29 28 29
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 7444ms
memory: 3568kb
input:
100 27 1 -219694090 2 313611706 3 19681553 4 -393439728 5 137039465 6 -210242538 7 -257014477 8 711593910 9 -126342644 10 317378740 12 -27880234 14 -312500245 15 -611623850 16 26965932 17 -344751802 19 25604908 20 -925684523 21 218732296 22 -906235432 23 128008760 24 128339229 25 -373435576 26 78643...
output:
29 29 29 29 29 29 29 29 29 28 28 29 29 29 28 29 29 29 29 29 29 29 29 29 29 28 28 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 29 28 29 28 29 29 29 29 28 29 29 29 28 29 29 29 29 28 28 29 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 28 29 28 29 29 29 29 29 29 29 29 29 28 29
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 7740ms
memory: 3696kb
input:
100 26 1 66877446 2 -164941227 3 225463507 4 184131912 5 102090525 7 758317818 8 -97450001 9 370239141 11 3046899 13 323733227 14 -130439971 16 -635446409 17 -859978167 18 48284039 19 -447989609 20 -127277242 21 557802358 22 101519428 23 62166242 24 -314606125 25 -689141632 26 -358169960 27 -4857611...
output:
29 29 28 29 29 29 28 29 29 29 29 29 29 28 29 29 28 28 29 29 29 29 29 29 28 29 28 27 29 27 28 29 29 29 29 29 28 29 29 28 29 28 29 29 29 29 28 28 29 29 29 29 29 29 29 29 29 29 28 29 28 29 28 27 29 29 28 29 29 29 29 29 29 29 29 29 29 29 29 28 29 28 29 29 29 29 29 29 29 29 29 28 29 28 29 29 28 28 29 29
result:
ok 100 numbers
Test #10:
score: -100
Time Limit Exceeded
input:
100 25 1 348246102 2 -750467389 3 -68044274 4 -686461116 5 -293360003 7 -262211929 8 669230593 9 -78704756 10 609746050 11 41527955 12 -497959309 14 -647052946 15 -588566559 16 -19571993 18 -540729853 19 146529178 20 -814716222 21 28809002 22 -486593284 24 330571691 25 -313603881 26 757285671 27 -65...
output:
29 29 27 29 27 29 28 29 28 28 29 29 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 27 28 29 29 29 29 29 28 29 29 28 27 28 29 29 29 27 28 29 27 28 28 29 29 29 28 28 29 29 28 29 28 29 29 29 27 28 29 29 29 28 29 28 29 29 29 29 28 28 29 27 29 29 28 29 29 27 29 29 27 29 29 29 29 29 28 29 29