QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562685#9285. Construct The Integership2077WA 1237ms8536kbC++23948b2024-09-13 20:01:572024-09-13 20:01:58

Judging History

This is the latest submission verdict.

  • [2024-09-13 20:01:58]
  • Judged
  • Verdict: WA
  • Time: 1237ms
  • Memory: 8536kb
  • [2024-09-13 20:01:57]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e7+5,lim=1e7;
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());
		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);
		}
		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<=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;
}

详细

Test #1:

score: 100
Accepted
time: 1212ms
memory: 8248kb

input:

2
12
2021

output:

48
-1

result:

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

Test #2:

score: 0
Accepted
time: 1237ms
memory: 8536kb

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

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
90
-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:

wrong answer 4th numbers differ - expected: '-1', found: '90'