Hi everyone! Welcome to the Stage 7 7 7 of this series of training contests. Cuber QQ is the problem settler of this contest; he has prepared 11 11 11 problems for you and wishes you to enjoy it. Good luck!
As the first problem of this contest, Cuber QQ thought that it’s reasonable to start with an easy one, so he modified the famous A + B A + B A+B problem by a little bit, so that it’s easy enough but not that trivial.
Given a , b , c a,b,c a,b,c , find an arbitrary set of x , y , z x,y,z x,y,z such that a × 1 0 x + b × 1 0 y = c × 1 0 z a\times 10^x+b\times 10^y=c\times 10^z a×10x+b×10y=c×10z and 0 ≤ x , y , z ≤ 1 0 6 0\leq x,y,z\leq 10^6 0≤x,y,z≤106.
The input consists of multiple test cases, starting with an integer t ( 1 ≤ t ≤ 100 ) t (1\leq t\leq 100) t(1≤t≤100), denoting the number of test cases.
For each test case, there are three space-separated integers, a , b , c a,b,c a,b,c respectively ( 1 ≤ a , b , c ≤ 1 0 100000 ) (1\leq a,b,c\leq 10^{100000}) (1≤a,b,c≤10100000).
For each test case, please output three space-separated integers x , y , z x,y,z x,y,z. If there are multiple solutions, print any of them.
In case there are no solutions, please output − 1 −1 −1 as a single line.
3
23 39 62
2 31 51
1 1 1
0 0 0
1 0 0
-1
HDOJ may give ambiguous feedback due to the compatibility issue of our checker. If you see “System Error”, please think of it as “Wrong Answer”.
2019 Multi-University Training Contest 7
#pragma GCC optimize(3)
#include
using namespace std;
const int maxn=2e5+10;
struct Hash{
int base[4],mod[4];
int tot,hash[4][maxn],pw[4][maxn];
Hash() {
tot=0;
for(int i=1;i<=3;i++) pw[i][0]=1;
base[1]=10;base[2]=10;base[3]=10;
mod[1]=1e9+7;mod[2]=998244353;mod[3]=1e9+9;
}
void init() {tot=0;}
void insert(int c) {
tot++;
for(int i=1;i<=2;i++) hash[i][tot]=(1LL*hash[i][tot-1]*base[i]+c)%mod[i];
for(int i=1;i<=2;i++) pw[i][tot]=(1LL*pw[i][tot-1]*base[i])%mod[i];
}
int query(int l,int r,int type) {
if(l==1) return hash[type][r];
return (hash[type][r]-(1LL*hash[type][l-1]*pw[type][r-l+1]%mod[type])+mod[type])%mod[type];
}
friend bool check(Hash &a,int l1,int r1,Hash &b,int l2,int r2,Hash &c,int l3,int r3) {
for(int i=1;i<=2;i++) if((a.query(l1,r1,i)+b.query(l2,r2,i))%a.mod[i]!=c.query(l3,r3,i)) return false;
return true;
}
}h[4];
char s[4][maxn];
int prel[4]; //记录字符串长度
int main()
{
int t;scanf("%d",&t);
for(int cas=1;cas<=t;cas++) {
int suf=0,pre=0;
for(int i=1;i<=3;i++) scanf("%s",s[i]+1),prel[i]=strlen(s[i]+1),h[i].init();
for(int i=1;i<=2;i++) {
int cnt=0;
for(int j=prel[i];s[i][j]=='0';j--) cnt++;
suf=max(suf,cnt); //0
pre=max(pre,prel[i]-suf); //非0
}
int des=max(prel[3],pre+suf+1); //初始化长度
for(int i=1;i<=3;i++) for(int j=1;j<=des;j++) h[i].insert(j<=prel[i]?s[i][j]-'0':0);
int x,y,z=des-prel[3];bool ok=false;
for(int i=prel[2];i<=des;i++) { //将a与c对齐,枚举b的长度
if(check(h[1],1,h[1].tot,h[2],1,i,h[3],1,h[3].tot)) {
x=des-prel[1],y=i-prel[2],ok=true;
break;
}
if(check(h[1],1,h[1].tot-1,h[2],1,i,h[3],1,h[3].tot)) {
x=des-prel[1]-1,y=i-prel[2],ok=true;
break;
}
}
if(ok) {printf("%d %d %d\n",x,y,z);continue;}
for(int i=prel[1];i<=des;i++) { //将b与c对齐,枚举a的长度
if(check(h[1],1,i,h[2],1,h[2].tot,h[3],1,h[3].tot)) {
x=i-prel[1],y=des-prel[2],ok=true;
break;
}
if(check(h[1],1,i,h[2],1,h[2].tot-1,h[3],1,h[3].tot)) {
x=i-prel[1],y=des-prel[2]-1,ok=true;
break;
}
}
if(ok) printf("%d %d %d\n",x,y,z);
else printf("-1\n");
}
}