QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#847200#5729. Carry Cam FailureYarema#AC ✓1ms3840kbC++201.5kb2025-01-07 18:47:172025-01-07 18:47:17

Judging History

This is the latest submission verdict.

  • [2025-01-07 18:47:17]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3840kb
  • [2025-01-07 18:47:17]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

string ans = "";
string s;
int len;

string mult(string t)
{
	string res(2 * SZ(t) - 1, '0');
	FOR (i, 0, SZ(t))
	{
		FOR (j, 0, SZ(t))
		{
			int x = (t[i] - '0') * (t[j] - '0') % 10;
			res[i + j] = (((res[i + j] - '0') + x) % 10) + '0';
		}
	}
	//cerr << t << ' ' << res << '\n';
	return res;
}

void upd(string t)
{
	reverse(ALL(t));
	if (ans.empty() || SZ(ans) > SZ(t))
		ans = t;
	if (ans > t)
		ans = t;
}

void f(string t)
{
	if (SZ(t) == len)
	{
		if (s == mult(t))
			upd(t);
		return;
	}
	FOR (d, 0, 10)
	{
		int res = 0;
		int pos = SZ(t);
		t += (d + '0');
		FOR (i, 0, pos + 1)
		{
			res += (t[i] - '0') * (t[pos - i] - '0');
			res %= 10;
		}
		//cerr << d << ' ' << t << ' ' << res << '\n';
		if (res == s[pos] - '0')
			f(t);
		t.pop_back();
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	if (SZ(s) % 2 == 0)
	{
		cout << -1 << '\n';
		return 0;
	}
	len = SZ(s) / 2 + 1;
	reverse(ALL(s));
	f("");
	if (ans.empty())
		cout << -1 << '\n';
	else
		cout << ans << '\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6

output:

4

result:

ok single line: '4'

Test #2:

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

input:

149

output:

17

result:

ok single line: '17'

Test #3:

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

input:

123476544

output:

11112

result:

ok single line: '11112'

Test #4:

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

input:

15

output:

-1

result:

ok single line: '-1'

Test #5:

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

input:

255768423183

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

45665732555

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

129862724660409

output:

11450607

result:

ok single line: '11450607'

Test #8:

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

input:

423019449793954427977

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

27121

output:

-1

result:

ok single line: '-1'

Test #10:

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

input:

1062062012267214086

output:

1086309746

result:

ok single line: '1086309746'

Test #11:

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

input:

7121439534552006831

output:

-1

result:

ok single line: '-1'

Test #12:

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

input:

2331

output:

-1

result:

ok single line: '-1'

Test #13:

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

input:

664

output:

42

result:

ok single line: '42'

Test #14:

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

input:

48960202843634584

output:

270467972

result:

ok single line: '270467972'

Test #15:

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

input:

950191368742123

output:

-1

result:

ok single line: '-1'

Test #16:

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

input:

6838729832825874768072709

output:

4195767732753

result:

ok single line: '4195767732753'

Test #17:

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

input:

126412441

output:

16521

result:

ok single line: '16521'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

4466447004844686806

output:

2609442604

result:

ok single line: '2609442604'

Test #19:

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

input:

4

output:

2

result:

ok single line: '2'

Test #20:

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

input:

90074858599988014

output:

-1

result:

ok single line: '-1'

Test #21:

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

input:

9498578088490196330623

output:

-1

result:

ok single line: '-1'

Test #22:

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

input:

82

output:

-1

result:

ok single line: '-1'

Test #23:

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

input:

8925123681749359895

output:

-1

result:

ok single line: '-1'

Test #24:

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

input:

9008004

output:

3008

result:

ok single line: '3008'