QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606154#9285. Construct The Integeryzj12345WA 1ms3652kbC++201.8kb2024-10-02 22:36:572024-10-02 22:36:58

Judging History

This is the latest submission verdict.

  • [2024-10-02 22:36:58]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3652kb
  • [2024-10-02 22:36:57]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
	int res = 0, bj = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') bj = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		res = res * 10 + ch - '0';
		ch = getchar();
	}
	return res * bj;
}
int gcd(int x, int y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}
int d[100];
int b[100], num[1000000], vis[1000000], ans[105];
void dfs(int dep)
{
	if (dep == 0)
	{
		int x = 0;
		for (int i = 1; i <= b[0]; i++) x = x * 10 + d[b[i]];
		num[++num[0]] = x; 
//		cout << x << "\n";
	}
	for (int i = 1; i <= d[0]; i++)
	{
		if (!vis[i]) 
		{
			vis[i] = 1;
			b[++b[0]] = i;
			dfs(dep - 1);
			b[0]--;
			vis[i] = 0;
		}
	}
}
int calc(int p)
{
	int x = p;
	d[0] = 0;
	while (x)
	{
		d[++d[0]] = x % 10;
		x /= 10;
	}
//	for (int i = 1; i <= d[0]; i++) cout << d[i] << " ";
//	cout << "\n";
	b[0] = num[0] = 0;
	for (int i = 1; i <= d[0]; i++) vis[i] = 0;
	dfs(d[0]);
	int g = 0;
	for (int i = 1; i <= num[0]; i++) g = gcd(g, num[i]);
	return g; 
}
signed main()
{
	ans[12] = 48, ans[15] = 5055, ans[18] = 288, ans[21] = 7077;
	ans[24] = 8088, ans[27] = 3699, ans[36] = 48888, ans[63] = 111888;
//	cout << calc(84) << "\n";
	int T;
	cin >> T;
	while (T--)
	{
		int x = read();
		if (x < 10) cout << x << "\n";
		else if (x < 100 && ans[x]) cout << ans[x] << "\n";
		else
		{
			int d[100] = {0};
			int y = x;
			while (y)
			{
				d[++d[0]] = y % 10;
				y /= 10;
			}
			int fl = 0;
			for (int i = 2; i <= d[0]; i++)
				if (d[i] != d[i - 1]) {
					fl = 1;
					break;
				}
			if (fl == 0) cout << x << "\n";
			else cout << -1 << "\n"; 
		}
	}
//	for (int i = 10; i <= 99; i++) cout << "i:" << i << " " << ans[i] << "\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

2
12
2021

output:

48
-1

result:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 3640kb

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: 0ms
memory: 3640kb

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: 0ms
memory: 3652kb

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

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

wrong answer 22nd numbers differ - expected: '5055555555', found: '-1'