QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454513#6407. Classical A+B ProblemASHWANTH_KRE 0ms3852kbC++142.9kb2024-06-25 00:04:482024-06-25 00:04:49

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 00:04:49]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3852kb
  • [2024-06-25 00:04:48]
  • 提交

answer



// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
		
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<pair<ll , ll>> vpll;
typedef vector<pair<ld , ld>> vplld;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef priority_queue<ll> pq;
typedef priority_queue<pair<ll,ll>> pqp;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define print(a) for(auto x:a) cout<<x<<" ";cout<<endl;
#define printarr(a , n) for(int i = 0 ; i < n  ;i ++) cout << a[i] << " "; cout << endl;
#define endl '\n'
#define sq(a) (a)*(a)
#define yes  cout << "YES" << endl;
#define no  cout << "NO" << endl;


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<int, null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define inf 1e18

int rand(int l, int r){
 	static mt19937 
 	rng(chrono::steady_clock::now().time_since_epoch().count());
 	uniform_int_distribution<int> ludo(l, r); 
 	return ludo(rng);
}


/*
	order_of_key(x) -> number of elements strictly smaller than x
	find_by_order(k) -> kth element 

	Good Life Good Wife

*/



string subtract(string x , string y)
{
	reverse(x.begin() , x.end());
	reverse(y.begin() , y.end());

	while(x.length() < y.length()){
		 x += '0';
	}
	while(x.length() > y.length()){
		 y += '0';
	}

//	cout << x << " " << y << endl;  

	vi ans;

	for(int i = 0 ; i < x.length() ; i ++)
	{
		int d1 = x[i] - '0';
		int d2 = y[i] - '0';
		int sb = d1 - d2;
		ans.pb(sb);
	}
	ans.pb(0);

	for(int i = 0 ; i < ans.size()-1; i++)
	{
		if(ans[i] < 0) 
		{
			ans[i] += 10;
			ans[i+1]--;
		}
	}

	while(ans.back() == 0) ans.pop_back();

	reverse(ans.begin() , ans.end());
	if(ans[0] < 0) return "-";

	string k = "";
	for(int x : ans)
	{
		k += (x + '0');
	}
	return k;
}

void solve()
{

	string s;
	cin >> s;

	int n = s.length();

	for(int d = 1 ; d <= 9 ; d ++)
	{

		for(int len = max(1 , n-1) ; len <= n ; len++)
		{
			string t = "";
			for(int i = 0 ; i < len ; i ++) t += d + '0';
	
			string u = subtract(s , t);


			if(u.length() && u[0] != '-')
			{
				bool ok = true;
				for(char c : u)
				{
					if(c != 0 && c == u[0]) continue;
					ok = false;
				}		

				if(ok)
				{
					cout<< u << " " << t << endl;
					return;
				}
			}
		}
	}



}
int main(){

	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" , stdin);
		freopen("output.txt", "w" , stdout);
	#endif

	int t=1;
	cin>>t;

	for(int i = 1 ; i <= t ; i ++)
	{
    	solve();
	}	
	return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

1 1
9 777
999 333
222 88888
2222222 111111
2 9999999999999999999999999999

result:

ok ok (6 test cases)

Test #2:

score: -100
Runtime Error

input:

100
854
77777777781111111111111111110
44444450
11111111111111333
2310
5
333333333333333333333343332
888999
10
11113333
335
77779
88888888888888888888889111111111111111111110
55555555555555777777
72222222222222222222221
666
5777
1111555555
444444444544444444443
88888888888891111111111110
673332
97
77...

output:


result: