QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#586130#2393. Alien IntegersTenshiAC ✓0ms3824kbC++201.7kb2024-09-24 06:21:272024-09-24 06:21:29

Judging History

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

  • [2024-09-24 06:21:29]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3824kb
  • [2024-09-24 06:21:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;

#define int ll

int n;
string s;
int len;
bool b[10];

signed main(){
	cin>>n;
	s=to_string(n);
	len=s.size();
	if(len==1){
		cout<<n-1<<" "<<n+1;
		return 0;
	}
	
	for(auto e: s) b[e-'0']=true;
	bool fl=true;
	rep(i, 0, 9) if(!b[i]) fl=false;
	if(fl){
		puts("Impossible");
		return 0;
	}
	vector<int> a;
	rep(i, 0, 9) if(!b[i]) a.pb(i);
	
	int x=-1, y=-1;
	
	int fir=s[0]-'0';
	rep(i, 0, fir-1){
		int val;
		if(i && b[i]) continue;
		int rec;
		dwn(i, 9, 0) if(!b[i]){
			rec=i;
			break;
		}
		if(!i){
			if(!rec){
				val=0;
			}
			else{
				val=stoll(string(len-1, rec+'0'));
			}
		}
		else{
			string tmp;
			tmp.pb(char(i+'0'));
			tmp+=string(len-1, rec+'0');
			val=stoll(tmp);
		}
		x=val;
	}
	
	int mn=0; // only zero?
	rep(i, 1, 9) if(!b[i]){
		mn=i;
		break;
	}
	if(mn){
		rep(i, fir+1, 9){
			if(i && b[i]) continue;
			
			string tmp;
			tmp.pb(char(i+'0'));
			if(!b[0]) tmp+=string(len-1, '0');
			else tmp+=string(len-1, '0'+mn);
			y=stoll(tmp);
			
			break;
		}	
		if(y==-1){
			// len+1
			string tmp;
			tmp.pb(char(mn+'0'));
			if(!b[0]) tmp+=string(len, '0');
			else tmp+=string(len, mn+'0');
			y=stoll(tmp);
		}
	}
	
	if(x==-1) cout<<y;
	else if(y==-1) cout<<x;
	else{
		if(n-x==y-n) cout<<x<<" "<<y;
		else if(n-x>y-n) cout<<y;
		else cout<<x;
	}
	
	return 0;
}

詳細信息

Test #1:

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

input:

1

output:

0 2

result:

ok single line: '0 2'

Test #2:

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

input:

394444

output:

288888 500000

result:

ok single line: '288888 500000'

Test #3:

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

input:

605555

output:

499999 711111

result:

ok single line: '499999 711111'

Test #4:

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

input:

944444

output:

888888 1000000

result:

ok single line: '888888 1000000'

Test #5:

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

input:

394444444444444

output:

288888888888888 500000000000000

result:

ok single line: '288888888888888 500000000000000'

Test #6:

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

input:

605555555555555

output:

499999999999999 711111111111111

result:

ok single line: '499999999999999 711111111111111'

Test #7:

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

input:

944444444444444

output:

888888888888888 1000000000000000

result:

ok single line: '888888888888888 1000000000000000'

Test #8:

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

input:

1000000000000000

output:

999999999999999

result:

ok single line: '999999999999999'

Test #9:

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

input:

102030405060708

output:

99999999999999

result:

ok single line: '99999999999999'

Test #10:

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

input:

807060504030201

output:

999999999999999

result:

ok single line: '999999999999999'

Test #11:

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

input:

11111111111111

output:

9999999999999

result:

ok single line: '9999999999999'

Test #12:

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

input:

4

output:

3 5

result:

ok single line: '3 5'

Test #13:

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

input:

2222222222222

output:

1999999999999

result:

ok single line: '1999999999999'

Test #14:

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

input:

1999999999999

output:

2000000000000

result:

ok single line: '2000000000000'

Test #15:

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

input:

100000000000009

output:

88888888888888

result:

ok single line: '88888888888888'

Test #16:

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

input:

90000000000001

output:

88888888888888

result:

ok single line: '88888888888888'

Test #17:

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

input:

9876543210000

output:

Impossible

result:

ok single line: 'Impossible'

Test #18:

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

input:

112233440056789

output:

Impossible

result:

ok single line: 'Impossible'

Test #19:

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

input:

998877661123450

output:

Impossible

result:

ok single line: 'Impossible'

Test #20:

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

input:

912357890016129

output:

444444444444444

result:

ok single line: '444444444444444'

Test #21:

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

input:

189765003210110

output:

44444444444444

result:

ok single line: '44444444444444'

Test #22:

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

input:

778899023235656

output:

1111111111111111

result:

ok single line: '1111111111111111'

Test #23:

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

input:

5

output:

4 6

result:

ok single line: '4 6'

Test #24:

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

input:

333301467899999

output:

255555555555555

result:

ok single line: '255555555555555'

Test #25:

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

input:

433301467899999

output:

522222222222222

result:

ok single line: '522222222222222'

Test #26:

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

input:

274613689526294

output:

0

result:

ok single line: '0'

Test #27:

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

input:

340039250762387

output:

111111111111111

result:

ok single line: '111111111111111'

Test #28:

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

input:

136418797906598

output:

222222222222222

result:

ok single line: '222222222222222'

Test #29:

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

input:

161072428972852

output:

33333333333333

result:

ok single line: '33333333333333'

Test #30:

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

input:

589602035803718

output:

444444444444444

result:

ok single line: '444444444444444'

Test #31:

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

input:

146863487601092

output:

55555555555555

result:

ok single line: '55555555555555'

Test #32:

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

input:

350039125347282

output:

66666666666666

result:

ok single line: '66666666666666'

Test #33:

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

input:

652956153048838

output:

777777777777777

result:

ok single line: '777777777777777'

Test #34:

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

input:

9

output:

8 10

result:

ok single line: '8 10'

Test #35:

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

input:

421200497362543

output:

88888888888888

result:

ok single line: '88888888888888'

Test #36:

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

input:

867410302085138

output:

999999999999999

result:

ok single line: '999999999999999'

Test #37:

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

input:

223344556677889

output:

111111111111111

result:

ok single line: '111111111111111'

Test #38:

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

input:

110044556677889

output:

33333333333333

result:

ok single line: '33333333333333'

Test #39:

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

input:

110022336677889

output:

55555555555555

result:

ok single line: '55555555555555'

Test #40:

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

input:

110022334455889

output:

77777777777777

result:

ok single line: '77777777777777'

Test #41:

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

input:

110022334455667

output:

99999999999999

result:

ok single line: '99999999999999'

Test #42:

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

input:

442233116677889

output:

500000000000000

result:

ok single line: '500000000000000'

Test #43:

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

input:

220033445577889

output:

166666666666666

result:

ok single line: '166666666666666'

Test #44:

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

input:

330011445566889

output:

277777777777777

result:

ok single line: '277777777777777'

Test #45:

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

input:

10

output:

9

result:

ok single line: '9'

Test #46:

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

input:

770022445566119

output:

833333333333333

result:

ok single line: '833333333333333'

Test #47:

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

input:

550022331166778

output:

499999999999999

result:

ok single line: '499999999999999'

Test #48:

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

input:

94

output:

88 100

result:

ok single line: '88 100'

Test #49:

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

input:

394

output:

288 500

result:

ok single line: '288 500'

Test #50:

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

input:

944

output:

888 1000

result:

ok single line: '888 1000'

Test #51:

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

input:

999

output:

1000

result:

ok single line: '1000'

Test #52:

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

input:

123456789

output:

0

result:

ok single line: '0'