QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#848567#5729. Carry Cam FailureLaVuna47AC ✓0ms3876kbC++202.1kb2025-01-08 22:08:582025-01-08 22:08:59

Judging History

This is the latest submission verdict.

  • [2025-01-08 22:08:59]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3876kb
  • [2025-01-08 22:08:58]
  • Submitted

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

vector<int> s;

bool bf(vector<int>& X, vector<int>& t, int p)
{
	if(p==sz(X))
	{
		return (t==s);
	}
	
	FOR(i,0,10)
	{
		auto tt=t;
		X[p] = i;

		FOR(j,0,sz(X))
			t[p+j]=(t[p+j]+(X[p]*X[j])%10)%10;

		FOR(j,0,p)
			t[p+j]=(t[p+j]+(X[j]*X[p])%10)%10;
	
		if(t[p]==s[p] && bf(X,t, p+1))
			return true;
		t=tt;
		X[p]=0;
	}
	return false;
}

int solve()
{
	string S;
	if(!(cin>>S))return 1;
	s.clear();
	for(auto item: S)
		s.pb(item-'0');
	if(sz(s) % 2 == 0)
	{
		cout<<"-1\n";
	}
	else
	{
		vector<int> X((sz(s)+1)/2, 0);
		vector<int> t(sz(s),0);
		if(bf(X,t,0))
		{
			for(auto item: X)
				cout<<item;
			cout<<'\n';
		}
		else cout<<"-1\n";
	}
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

6

output:

4

result:

ok single line: '4'

Test #2:

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

input:

149

output:

17

result:

ok single line: '17'

Test #3:

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

input:

123476544

output:

11112

result:

ok single line: '11112'

Test #4:

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

input:

15

output:

-1

result:

ok single line: '-1'

Test #5:

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

input:

255768423183

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

45665732555

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

129862724660409

output:

11450607

result:

ok single line: '11450607'

Test #8:

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

input:

423019449793954427977

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

27121

output:

-1

result:

ok single line: '-1'

Test #10:

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

input:

1062062012267214086

output:

1086309746

result:

ok single line: '1086309746'

Test #11:

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

input:

7121439534552006831

output:

-1

result:

ok single line: '-1'

Test #12:

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

input:

2331

output:

-1

result:

ok single line: '-1'

Test #13:

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

input:

664

output:

42

result:

ok single line: '42'

Test #14:

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

input:

48960202843634584

output:

270467972

result:

ok single line: '270467972'

Test #15:

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

input:

950191368742123

output:

-1

result:

ok single line: '-1'

Test #16:

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

input:

6838729832825874768072709

output:

4195767732753

result:

ok single line: '4195767732753'

Test #17:

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

input:

126412441

output:

16521

result:

ok single line: '16521'

Test #18:

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

input:

4466447004844686806

output:

2609442604

result:

ok single line: '2609442604'

Test #19:

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

input:

4

output:

2

result:

ok single line: '2'

Test #20:

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

input:

90074858599988014

output:

-1

result:

ok single line: '-1'

Test #21:

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

input:

9498578088490196330623

output:

-1

result:

ok single line: '-1'

Test #22:

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

input:

82

output:

-1

result:

ok single line: '-1'

Test #23:

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

input:

8925123681749359895

output:

-1

result:

ok single line: '-1'

Test #24:

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

input:

9008004

output:

3008

result:

ok single line: '3008'