QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562672#9285. Construct The Integership2077WA 631ms7036kbC++23823b2024-09-13 19:59:172024-09-13 19:59:17

Judging History

This is the latest submission verdict.

  • [2024-09-13 19:59:17]
  • Judged
  • Verdict: WA
  • Time: 631ms
  • Memory: 7036kb
  • [2024-09-13 19:59:17]
  • 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;int cur=0;
		for (int s=x;s;s/=10)
			vec.emplace_back(s%10);
		sort(vec.begin(),vec.end());
		for (auto x:vec) cur=cur*10+x;
		g[cur]=__gcd(g[cur],x);
		for (int d=1;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: 631ms
memory: 7036kb

input:

2
12
2021

output:

48
-1

result:

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

Test #2:

score: -100
Wrong Answer
time: 628ms
memory: 6972kb

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

wrong answer 7th numbers differ - expected: '8088', found: '-1'