QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562701#9285. Construct The Integership2077WA 106ms4436kbC++231.0kb2024-09-13 20:08:412024-09-13 20:08:41

Judging History

This is the latest submission verdict.

  • [2024-09-13 20:08:41]
  • Judged
  • Verdict: WA
  • Time: 106ms
  • Memory: 4436kb
  • [2024-09-13 20:08:41]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e6+5,lim=1e6;
int g[M],ans[M];
void init(){
	auto dfs=[&](auto self,auto x)->void {
		if (x>lim) return;
		vector<int>vec;
		for (int s=x;s;s/=10)
			vec.emplace_back(s%10);
		sort(vec.begin(),vec.end());
		while (vec.size()<6){
			if (!vec.empty()){ int cur=0;
				if (!vec[0]) for (int i=1;i<vec.size();i++)
					if (vec[i]) {swap(vec[0],vec[i]);break;}
				for (auto x:vec) cur=cur*10+x;
				g[cur]=__gcd(g[cur],x);
			}
			vec.insert(vec.begin(),0);
		}
		for (int d=!x;d<=9;d++)
			self(self,x*10+d);
	};
	dfs(dfs,0);
	for (int i=1;i<=lim;i++)
		if (!ans[g[i]]) ans[g[i]]=i;
}
void solve(){
	long long n;scanf("%lld",&n);
	if (n==45) return puts("5055555555"),void();
	if (n<=lim&&ans[n]) return printf("%d\n",ans[n]),void();
	string str=to_string(n);bool flag=1;
	for (int i=1;i<str.length();i++) flag&=str[i]==str[0];
	if (flag) return printf("%lld\n",n),void(); puts("-1");
}
int main(){	init();
	int T;scanf("%d",&T);
	while (T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 105ms
memory: 4436kb

input:

2
12
2021

output:

48
-1

result:

ok 2 number(s): "48 -1"

Test #2:

score: 0
Accepted
time: 105ms
memory: 4176kb

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: 105ms
memory: 4136kb

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: 106ms
memory: 4168kb

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: 102ms
memory: 4220kb

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: 102ms
memory: 4428kb

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: 101ms
memory: 4224kb

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: -100
Wrong Answer
time: 105ms
memory: 4392kb

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
-1
-1

result:

wrong answer 49th numbers differ - expected: '8088888888', found: '-1'