MatrixGroup's Unknown Round 题解
MatrixGroup · · 个人记录
微观戏剧(Constructive ver.)
根据 P11275 微观戏剧 的结论,
若
在
时间复杂度
int t;ll z;
int main()
{
ios_base::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>z;
if(z==1) cout<<"-1 -1\n";
else if(z==0) cout<<"1 1\n";
else if(z<=10) cout<<1<<" "<<z<<"\n";
else if(z&1) cout<<z/2<<" "<<z/2+1<<"\n";
else cout<<z/2-1<<" "<<z/2+1<<"\n";
}
return 0;
}
GCD 与 LCM 问题 - 副本
:::warning[Warning]{open} 本题很魔怔。比赛页面应该告诉你这点了(?)。 :::
这点在题目里也有暗示:写的是找出三个正整数而不是构造,这提示我们本题或许需要一些暴力一点的想法。
先分析一些性质:
计算上界可得,
此时有
那么有
如果从
可以发现,
考虑令
注意可以
一个小优化是在奇数
不加这个优化的话,经过打表验证,判断互质的次数不会超过
std 最慢点 405ms。
void solve(int a)
{
if(a&1)
{
int x=int(sqrt(a));if(x==1)x=2;
for(int c=x;;++c)
{
int d=(a+c)/(c-1)+1;int b=c*d+1-c-d-a;
if(Coprime(c,d)&&Coprime(b,a%b))
{
cout<<b<<" "<<c<<" "<<d<<"\n";
return ;
}
}
}
else
{
int x=int(sqrt(a*2));if(x&1)++x;if(x==2)x=4;
for(int c=x;;++++c)
{
int d=(a+c)*2/(c-2)+1;if(d&1)++d;int b=c*d/2+1-c-d-a;
if(Coprime(c/2,d/2)&&Coprime(b,a%b))
{
cout<<b<<" "<<c<<" "<<d<<"\n";
return ;
}
}
}
return ;
}
世界沉睡童话Nirvana
不妨设
考虑
因为这个时候
考虑优化值域。考虑到即使有相邻两个相同的
void construct(int n,ll c)
{
if(n==3)
{
if(c==0)
{
a[1]=2;a[2]=3;a[3]=3;return ;
}
else
{
a[1]=1;a[2]=1;a[3]=1;return ;
}
}
ll val=(n-1)*(n-2ll)/2;
if(c>=val)
{
a[n]=1;construct(n-1,c-val);return ;
}
a[1]=2;a[2]=n-1;
for(int i=n;i>=3;--i)
{
if(c>=(i-2))
{
ok[i]=true;c-=i-2;
}
else
{
ok[i]=false;
}
}
for(int i=3;i<=n;++i)
{
a[i]=a[i-1];
if((ok[i])!=(a[i]%2==0)) ++a[i];
if(a[i]==a[i-1]&&a[i-1]==a[i-2]) ++++a[i];
}
}
talent
:::warning[Warning]{open} 本题有些魔怔。 :::
首先判掉无解:
像之前那题一样,考虑是不是会做部分分就会做正解了。如果会做
既然想要构造倒着读是
考虑
问题来了,怎么找到基础的数满足倒着读是
数据基本上是随的,因为那
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,del##i##verme=int(n);i<del##i##verme;++i)
#define rep1(i,n) for(int i=1,parano##i##a=int(n);i<=parano##i##a;++i)
#define per(i,n) for(int i=int(n)-1;i>=0;--i)
#define per1(i,n) for(int i=int(n);i>=1;--i)
#define pb push_back
typedef long long ll;
using namespace std;
const ll MOD=1853020188851841;
const ll INV10=1667718169966657;
const string S1[3]={"1798704148353101310821220","7140001059674172358223121","1130701152661116363835281"};
const int V1[3]={376247,1425686,87693},L1=25,N1=3;
const string S2[9]={
"48527259262822912032","22262502148278718932","09764136364071435813",
"87331050093413758914","35216231262456287565","23385310593363922617",
"02227593544855064037","29164052251854382347","23057321528911244778"};
const int V2[9]={33653,36728,37997,25995,11773,45760,20752,37352,44954},L2=20,N2=9;
const string S3[15]={
"29022266224263222","33937055426298042","47752934628224952","51677723820359772",
"65492612032384692","79218401234310513","83133399336345333","97948188538370253",
"02863077730406073","16688856932431983","20504745144466704","34329534346491624",
"48144423548427444","52069212740552364","66874101942587184"};
const int V3[15]={31779,54495,13041,35559,52713,30159,18207,58176,46539,3906,1665,21204,51822,5391,37341},L3=17,N3=15;
const int N=531441,K=59049;
int dp1[N*3],lst1[N*3],tp1[N*3];
int dp2[K],lst2[K],tp2[K];
int dp3[K],lst3[K],tp3[K];
int cnt,q[N*3+2];
ll pw10[999],pw110[999];
const int F1=146,F2=70,F3=55;
string restore1(ll x)
{
string ans="";
rep(j,F1-dp1[x]) ans+='0';
while(x!=0)
{
ans+=S1[tp1[x]];
rep(j,dp1[x]-dp1[lst1[x]]-L1) ans+="0";
x=lst1[x];
}
return ans;
}
string restore2(ll x)
{
string ans="";
rep(j,F2-dp2[x]) ans+='0';
while(x!=0)
{
ans+=S2[tp2[x]];
rep(j,dp2[x]-dp2[lst2[x]]-L2) ans+="0";
x=lst2[x];
}
return ans;
}
string restore3(ll x)
{
string ans="";
rep(j,F3-dp3[x]) ans+='0';
while(x!=0)
{
ans+=S3[tp3[x]];
rep(j,dp3[x]-dp3[lst3[x]]-L3) ans+="0";
x=lst3[x];
}
return ans;
}
ll Eval(const string&Ss)
{
ll ret=0;
rep(i,Ss.size()) ret=(ret*10+int(Ss[i]&15))%MOD;
return ret;
}
int k;
int v[20];
void solve(const int C,int const*V,const int L,int *dp,int *lst,int *tp,const int mod,const int expected)
{
memset(dp,0x3f,sizeof(int)*mod);
dp[0]=0;q[cnt=1]=0;
rep(i,C) v[i]=V[i]%mod;
for(int cur=0;;++cur)
{
int l=cnt;
rep1(i,l)
{
int ver=q[i];
if(dp[ver]>cur) break;
for(int j=0;j<C;++j)
{
int nw=ver+v[j];if(nw>=mod)nw-=mod;
if(dp[nw]==0x3f3f3f3f)
{
dp[nw]=cur+L;
lst[nw]=ver;tp[nw]=j;
q[++cnt]=nw;
}
}
}
rep(i,C) v[i]=v[i]*10%mod;
if(cnt==expected)
{
break;
}
}
int mx=0;rep(i,mod) if(i%(mod/expected)==0) mx=max(mx,dp[i]);
}
const int L=F1+F2+F3+16+1;
ll a,b;
string ans;
// | --16-- | -------55-------- | --------70-------- | -----------146----------- | 1 |
void query()
{
cin>>a>>b;
if(a%9!=b%9)
{
cout<<"-1\n";return ;
}
ll pw=pw10[L-1];
ans="";
rep(i,L) ans+='0';
ans[L-1]='1';
ll val=b-pw+MOD;while(val%10==0)val+=MOD;
rep(i,16)
{
ans[i]=char(48|(val%10));
val/=10;
}
ll c=a-Eval(ans);if(c<0)c+=MOD;
c=ll(__int128(c)*pw110[1+F1+F2]%MOD);
string qq=restore3(c%(K));
rep(i,F3) ans[16+i]=qq[i];
c=a-Eval(ans);if(c<0)c+=MOD;
c=ll(__int128(c)*pw110[1+F1]%MOD);
qq=restore2(c/K%(K/3));
rep(i,F2) ans[16+F3+i]=qq[i];
c=a-Eval(ans);if(c<0)c+=MOD;
c=ll(__int128(c)*pw110[1]%MOD);
qq=restore1(c/K/(K/3));
rep(i,F1) ans[16+F3+F2+i]=qq[i];
cout<<ans<<'\n';
}
int main()
{
solve(N1,V1,L1,dp1,lst1,tp1,N*3,N*3);
solve(N2,V2,L2,dp2,lst2,tp2,K/3,K/3);
solve(N3,V3,L3,dp3,lst3,tp3,K,K/9);
pw10[0]=1;rep1(i,500)pw10[i]=pw10[i-1]*10%MOD;
pw110[0]=1;rep1(i,500)pw110[i]=ll(__int128(pw110[i-1])*INV10%MOD);
ios_base::sync_with_stdio(false);cin.tie(0);int t;cin>>t>>k;
while(t--)query();
return 0;
}