QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61025#3889. Balanced BreakdownSayedHassan#AC ✓2ms3452kbC++2.3kb2022-11-09 07:52:482022-11-09 07:52:49

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-09 07:52:49]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3452kb
  • [2022-11-09 07:52:48]
  • Submitted

answer


#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define sc second

/*const int N=1e5+5;
int n,m;
int c[N],a[N],b[N],p[N];*/
bool pal(ll x)
{
    string s=to_string(x);
    int l=0,r=s.size()-1,ch=0;
    while(l<=r)
    {
        if(s[l]!=s[r])ch=1;
        l++;
        r--;
    }
    if(ch)return false;
    return true;
}
int main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	/*cin>>n>>m;
	for(int i=0;i<m;i++)
	{
	    cin>>c[i]>>a[i];
	    p[c[i]]=a[i];
	}
	for(int i=0;i<n;i++)
	{
	    cin>>b[i];
	}*/
	ll x;
	cin>>x;
	string s=to_string(x);
	vector<ll> v;
	while(x)
	{
	    int l=0,r=s.size()-1,ch=0;
	    while(l<=r)
        {
            if(s[l]!=s[r])ch=1;
            l++;
            r--;
        }
        if(!ch)
        {
            v.push_back(x);
            break;
        }
		int cnt=0;
		int lst=0;
		for(int i=0; i<s.size()/2; i++)
		{
			if(s[i]!='0')
				lst=i;
		}
		string t;
		if(s[lst]=='1'&&lst==0)
		{
			for(int i=0; i<s.size()-1; i++)
				t.push_back('9');
		}
		else
		{
			for(int i=0; i<lst; i++)
				t.push_back(s[i]);
			t.push_back(max((char)(s[lst]-1),'0'));
			for(int i=lst; i<s.size()/2-1; i++)
				t.push_back('9');
			if(s.size()%2)
				t.push_back('9');
			int sz=t.size()-1;
			if(s.size()%2==1)
				sz--;
			for(int i=sz; i>=0; i--)
			{
				t.push_back(t[i]);
			}

		}
		if(s.size()==2&&s[0]!='1')
		{
			t.clear();
			t.push_back(s[0]-1);
			t.push_back(s[0]-1);
		}
		if(s.size()==1)
		{
			v.push_back(x);
			break;
		}
		string t2;
		for(int i=0;i<s.size()-1;i++)t2.push_back((char)(s[0]-1));
		ll temp=stoll(t),temp2=stoll(t2);
		//temp=max(temp,temp2);
		x-=temp;
		s=to_string(x);
		v.push_back(temp);
	}
	for(int k=0;k<=100;k++)
    {

	for(int i=0;i<v.size();i++)
    {
        for(int j=i+1;j<v.size();j++)
        {
            if(pal(v[i]+v[j]))
            {
                v[i]+=v[j];
                v[j]=0;
            }
        }
    }
    }
    vector<ll> ans;
    for(auto x:v)if(x)ans.push_back(x);
	cout<<ans.size()<<endl;
	for(auto x:ans)
		cout<<x<<endl;
	return 0;
}

詳細信息

Test #1:

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

input:

1100000

output:

2
1099901
99

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

1000

output:

2
999
1

result:

ok 

Test #3:

score: 0
Accepted
time: 2ms
memory: 3320kb

input:

10

output:

2
9
1

result:

ok 

Test #4:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

11005

output:

3
10901
99
5

result:

ok 

Test #5:

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

input:

100000000000000000

output:

2
99999999999999999
1

result:

ok 

Test #6:

score: 0
Accepted
time: 2ms
memory: 3256kb

input:

21

output:

3
11
9
1

result:

ok 

Test #7:

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

input:

1234567887664321

output:

5
1234567777654321
109999901
9999
99
1

result:

ok 

Test #8:

score: 0
Accepted
time: 2ms
memory: 3296kb

input:

690231482249788720

output:

7
690231481184132096
1065555601
100001
999
11
9
3

result:

ok 

Test #9:

score: 0
Accepted
time: 2ms
memory: 3452kb

input:

319173294485481281

output:

7
319173293392371913
1093003901
104401
999
55
9
3

result:

ok 

Test #10:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

761353558778227546

output:

7
761353557755353167
1022772201
101101
999
66
9
3

result:

ok 

Test #11:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

947179993313410328

output:

7
947179992299971749
1013333101
104401
999
66
9
3

result:

ok 

Test #12:

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

input:

171408535476134406

output:

7
171408534435804171
1040220401
108801
999
22
9
3

result:

ok 

Test #13:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

896452012199589977

output:

7
896452011110254698
1089229801
104401
999
66
9
3

result:

ok 

Test #14:

score: 0
Accepted
time: 2ms
memory: 3452kb

input:

970894988875162603

output:

7
970894987789498079
1085555801
107701
999
11
9
3

result:

ok 

Test #15:

score: 0
Accepted
time: 2ms
memory: 3296kb

input:

200429647731477537

output:

7
200429646646924002
1084444801
107701
999
22
9
3

result:

ok 

Test #16:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

960284896260606337

output:

6
960284895598482069
662090266
33933
55
9
5

result:

ok 

Test #17:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

999999999999999999

output:

1
999999999999999999

result:

ok 

Test #18:

score: 0
Accepted
time: 2ms
memory: 3248kb

input:

1

output:

1
1

result:

ok 

Test #19:

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

input:

7

output:

1
7

result:

ok 

Test #20:

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

input:

487291873378192784

output:

1
487291873378192784

result:

ok 

Test #21:

score: 0
Accepted
time: 2ms
memory: 3308kb

input:

414821987097225805

output:

5
414821986689128414
407999704
96969
696
22

result:

ok 

Test #22:

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

input:

418581849637933703

output:

6
418581848848185814
789696987
49994
898
9
1

result:

ok 

Test #23:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

607979478938276336

output:

6
607979477774979706
1163113611
182281
696
33
9

result:

ok 

Test #24:

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

input:

471913902748260172

output:

6
471913901109319174
1638888361
51915
707
9
6

result:

ok 

Test #25:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

1000003

output:

2
999999
4

result:

ok 

Test #26:

score: 0
Accepted
time: 2ms
memory: 3324kb

input:

123456788654328

output:

3
123456696654321
91999919
88

result:

ok