QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563720 | #9285. Construct The Integer | zjy0001 | WA | 148ms | 4284kb | C++17 | 1.6kb | 2024-09-14 15:26:40 | 2024-09-14 15:26:40 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
map<LL,LL>ans;
int a[20],f[100000];
inline bool chk(LL n){
LL c=n%10;
while(n/=10)if(n%10!=c)return 0;
return 1;
}
inline void dfs(int x){
if(x==5){
vector<int>d;
do{
int x=0;for(int i=0;i<5;++i)x=x*10+a[i];
d.emplace_back(x);
}while(next_permutation(a,a+5));
sort(a,a+5);
for(auto i:d)for(auto j:d)
if(to_string(i).length()>=to_string(j).length())
f[i]=__gcd(f[i],j);
}
else for(int i=x?a[x-1]:0;i<10;++i)a[x]=i,dfs(x+1);
}
inline LL calc(LL n){
LL h=n;
int m=0;
for(auto i:to_string(n))a[m++]=i&15;
sort(a,a+m);
do{
LL x=0;for(int i=0;i<m;++i)x=x*10+a[i];
h=__gcd(h,x);
}while(next_permutation(a,a+m));
return h;
}
inline void solve(LL n,LL c,int k){
auto h=calc(n);
if(!ans.count(h))ans[h]=n;
else ans[h]=min(ans[h],n);
if(n>1e17)return;
solve(n*10+c,c,k);
if(k)solve(n*10,c,0);
}
inline void init(){
iota(f+1,f+100000,1);
dfs(0);
for(int i=1;i<100000;++i)
if(!ans.count(f[i]))ans[f[i]]=i;
else ans[f[i]]=min(ans[f[i]],1ll*i);
for(int c=1;c<10;++c)solve(c,c,1);
}
inline void MAIN(){
LL n;cin>>n;
if(chk(n))cout<<n<<'\n';
else cout<<(ans.count(n)?ans[n]:-1)<<'\n';
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
init();
int t=1;cin>>t;while(t--)MAIN();
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 148ms
memory: 4024kb
input:
2 12 2021
output:
48 -1
result:
ok 2 number(s): "48 -1"
Test #2:
score: 0
Accepted
time: 147ms
memory: 3988kb
input:
50 162281868021198482 843590795441798975 22222 149588437607469906 802011151087104980 6059547534408460 24 666666 2 76 29 44 6666666 333333 694875412087041404 203911016125660313 33333333333333333 621646568444724049 363434583954291856 33333333333333 7777777777777777 308242055812053607 65243634304254533...
output:
-1 -1 22222 -1 -1 -1 8088 666666 2 -1 -1 44 6666666 333333 -1 -1 33333333333333333 -1 -1 33333333333333 7777777777777777 -1 -1 -1 888 -1 4444444444 -1 3333333333333333 88888888 888888888888 88 -1 3333333333333 -1 555 -1 48888 222222222222 -1 -1 -1 -1 -1 -1 -1 11 -1 -1 55555555555555555
result:
ok 50 numbers
Test #3:
score: 0
Accepted
time: 147ms
memory: 4024kb
input:
50 841731922341882973 172755266467187037 129493702112701195 90 273793122414069242 593694707008455288 502545216673419533 721595990997982386 93377610984612549 87 863812025013802109 234122432773362066 123027939432443575 88888 47 222222222222222222 852841820206347862 74 423472610938208849 94 15762310812...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 88888 -1 222222222222222222 -1 -1 -1 -1 -1 -1 -1 22222222 -1 -1 -1 -1 -1 -1 -1 -1 333333333333333 -1 -1 -1 1111111111111111 -1 -1 -1 4 333333333 -1 33333333 -1 1 444444444444444444 5055 -1 4444444444444444
result:
ok 50 numbers
Test #4:
score: 0
Accepted
time: 148ms
memory: 4280kb
input:
50 66666666 89 11111111111111111 89013034181000726 33 285627919192884437 8888888888 425171425350891250 71 7 987944414171602593 301305598619697018 193193702519217107 413499651741453076 476551385483571548 13 668044926137832393 66666666666666 536187734191891003 386045016440405474 592806051753396502 805...
output:
66666666 -1 11111111111111111 -1 33 -1 8888888888 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 66666666666666 -1 -1 -1 -1 4444444 666666666666666 -1 -1 -1 666666666666666666 -1 -1 -1 -1 -1 33 -1 -1 -1 -1 77777777777 -1 -1 8888888 -1 -1 -1 -1 -1 -1 -1 66
result:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 148ms
memory: 4080kb
input:
50 21839873092357856 640219260799980486 522525742014723888 725988133037119616 290913044663852094 555555 333 85 11111111 631169318889705610 555555555555 69 323842199157642120 333333333333333333 78 4444444444444 99 11111111111 174059246927999752 377574503599716306 777777777 45 77777777777777 471255439...
output:
-1 -1 -1 -1 -1 555555 333 -1 11111111 -1 555555555555 -1 -1 333333333333333333 -1 4444444444444 99 11111111111 -1 -1 777777777 5055555555 77777777777777 -1 -1 -1 -1 -1 666 -1 3699 11111 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 222222 777
result:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 147ms
memory: 3988kb
input:
50 134845565732593935 935387048910748709 664860202421625603 111111111111 94225248889089695 879054556667480931 83 256931203846046588 92 3333333333 643572951492602142 49 822981260158260819 82526944128792584 77 179102579989215254 444444444444444 903288965370689433 799584023203226863 495718727325977077 ...
output:
-1 -1 -1 111111111111 -1 -1 -1 -1 -1 3333333333 -1 -1 -1 -1 77 -1 444444444444444 -1 -1 -1 9 55555555555 66666666666 -1 -1 7077 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 444444444444 111111111111111111 -1 777777 -1 1111111 -1 -1 -1 5555555 -1 -1
result:
ok 50 numbers
Test #7:
score: 0
Accepted
time: 148ms
memory: 3984kb
input:
50 521060787741107580 23 676105575462225385 381451598031262925 163853609803189968 6666666666 444444444 5413279537561410 8888 627586599810900678 26 42 55555555555555 43 916143781173401889 84324828731964774 57 502764983190081253 563324731189331234 53 993638134797830048 3 52966605322057444 333333333333...
output:
-1 -1 -1 -1 -1 6666666666 444444444 -1 8888 -1 -1 -1 55555555555555 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 333333333333 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11111111111111 -1 -1 -1 44444444 -1 -1 -1
result:
ok 50 numbers
Test #8:
score: 0
Accepted
time: 147ms
memory: 3992kb
input:
50 888888888888888 56 877835694720649559 952720572201731456 335408917861649366 66666 2222222222222 2222222222222222 60 787629613935422754 776076510839296560 630192867080657053 88888888888 77 371026816893229896 540950482791116710 1111 438538728083004091 1111111111111 692477168467510300 14875591187121...
output:
888888888888888 -1 -1 -1 -1 66666 2222222222222 2222222222222222 -1 -1 -1 -1 88888888888 77 -1 -1 1111 -1 1111111111111 -1 -1 -1 111 444 -1 44444444444 -1 -1 -1 55555555 222 7777777777 -1 555555555555555555 -1 -1 -1 66 -1 3333 -1 -1 77777777 -1 22222222222 -1 -1 -1 8088888888 -1
result:
ok 50 numbers
Test #9:
score: 0
Accepted
time: 148ms
memory: 3992kb
input:
50 59 51 661302813816248549 22 192583020404011827 17 44444444444444 91 586662754350034562 398400101471708497 101765673897273715 950257034940091202 675282347327966568 262324075672299484 55 116841977139981012 907267074306890738 731741654713115120 33333333333 95 111111111 49465410047628729 676526945279...
output:
-1 -1 -1 22 -1 -1 44444444444444 -1 -1 -1 -1 -1 -1 -1 55 -1 -1 -1 33333333333 -1 111111111 -1 -1 88888888888888 -1 666666666666 -1 7777 -1 -1 -1 666666666 -1 -1 -1 -1 -1 -1 6666666666666 -1 -1 -1 6 -1 3333333 -1 -1 -1 -1 5
result:
ok 50 numbers
Test #10:
score: 0
Accepted
time: 147ms
memory: 4284kb
input:
50 52 575309381208032699 5555555555555 266726083774034829 542826291792345757 7777777 851387910588959345 769483004587345130 66666666666666666 444444 753084815602287766 21314793613364329 555555555555555 5555 55555 802650828045480305 59132663174616906 18 107332661275127473 33333 22222222222222 70482262...
output:
-1 -1 5555555555555 -1 -1 7777777 -1 -1 66666666666666666 444444 -1 -1 555555555555555 5555 55555 -1 -1 288 -1 33333 22222222222222 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 44444 -1 -1 -1 -1 -1 555555555 -1 -1 8888888888888888 -1 -1 -1 -1 -1 -1 -1
result:
ok 50 numbers
Test #11:
score: -100
Wrong Answer
time: 147ms
memory: 4016kb
input:
50 777777777777777 838885201040309576 7777777777777 349993004923079131 961905130001849922 44 888888888 494205937842636532 88 665229069533206603 676042795298310688 704087678909665196 148049062628894820 81 58 615812229161736595 758551024807498420 819875141880896223 922348607469188267 8888888888888 168...
output:
777777777777777 -1 7777777777777 -1 -1 44 888888888 -1 88 -1 -1 -1 -1 9099999999 -1 -1 -1 -1 -1 8888888888888 -1 -1 -1 -1 2222 -1 -1 888888888888888888 -1 5555555555 5555555555555555 -1 6066666666 -1 -1 -1 -1 -1 -1 111111111111111 -1 777777777777777777 -1 -1 77777 -1 99 -1 55 -1
result:
wrong answer 33rd numbers differ - expected: '222888888', found: '6066666666'