QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#434013 | #2393. Alien Integers | JustJie# | AC ✓ | 1ms | 3844kb | C++20 | 2.7kb | 2024-06-08 14:14:26 | 2024-06-08 14:14:26 |
Judging History
answer
/***************************************************************************************************
* author : Jie Chen (4th Year CS)
* school : Rochester Institute of Technology
* created: 06.08.2024 01:43:30
****************************************************************************************************/
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
constexpr int ALL = (1 << 10) - 1;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i64 N;
cin >> N;
int mask = 0;
for (i64 x = N; x; x /= 10) {
int d = x % 10;
mask |= (1 << d);
}
mask ^= ALL;
string s = to_string(N);
if (mask == 0) {
cout << "Impossible\n";
} else {
int mi = 10;
int ma = -1;
int f = s[0] - '0';
int ff = -1;
int ss = -1;
int mi2 = 10;
for (int i = 0; i < 10; i++) {
if (mask & (1 << i)) {
if (mi != 10) {
mi2 = min(mi2, i);
}
mi = min(mi, i);
ma = max(ma, i);
if (i < f) {
ff = i;
} else if (ss == -1) {
ss = i;
}
}
}
vector<i64> ans;
string ans1, ans3 = "0";
if (ff != -1) {
ans1 = string(1, ff + '0');
} else {
ans1 = "0";
}
while (ans1.size() != s.size()) {
ans1 += char(ma + '0');
}
while (ans3.size() != s.size()) {
ans3 += char(ma + '0');
}
ans.push_back(stoll(ans1));
ans.push_back(stoll(ans3));
string ans2, ans4;
if (ss != -1) {
ans2 = string(1, ss + '0');
} else {
ans2 = "0";
}
if (mi == 0) {
if (mi2 != 10) {
ans4 = string(1, mi2 + '0');
}
}
while (ans2.size() != s.size()) {
ans2 += char(mi + '0');
}
while (ans4.size() < s.size() + 1) {
ans4 += char(mi + '0');
}
ans.push_back(stoll(ans2));
ans.push_back(stoll(ans4));
vector<i64> res {ans[0]};
i64 piv = ans[0];
for (i64 x : ans) {
if (abs(x - N) < abs(piv - N)) {
res.clear();
res.push_back(x);
} else if (abs(x - N) == abs(piv - N)) {
res.push_back(x);
}
}
set<i64> uni(res.begin(), res.end());
for (i64 x : uni) {
cout << x << " ";
}
}
}
// ~ Just Jie
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
1
output:
0 2
result:
ok single line: '0 2 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
394444
output:
288888 500000
result:
ok single line: '288888 500000 '
Test #3:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
605555
output:
499999 711111
result:
ok single line: '499999 711111 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
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: 3624kb
input:
605555555555555
output:
499999999999999 711111111111111
result:
ok single line: '499999999999999 711111111111111 '
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
944444444444444
output:
888888888888888 1000000000000000
result:
ok single line: '888888888888888 1000000000000000 '
Test #8:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1000000000000000
output:
999999999999999
result:
ok single line: '999999999999999 '
Test #9:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
102030405060708
output:
99999999999999
result:
ok single line: '99999999999999 '
Test #10:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
807060504030201
output:
999999999999999
result:
ok single line: '999999999999999 '
Test #11:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
11111111111111
output:
9999999999999
result:
ok single line: '9999999999999 '
Test #12:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
4
output:
3 5
result:
ok single line: '3 5 '
Test #13:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
2222222222222
output:
1999999999999
result:
ok single line: '1999999999999 '
Test #14:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1999999999999
output:
2000000000000
result:
ok single line: '2000000000000 '
Test #15:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
100000000000009
output:
88888888888888
result:
ok single line: '88888888888888 '
Test #16:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
90000000000001
output:
88888888888888
result:
ok single line: '88888888888888 '
Test #17:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
9876543210000
output:
Impossible
result:
ok single line: 'Impossible'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
112233440056789
output:
Impossible
result:
ok single line: 'Impossible'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
998877661123450
output:
Impossible
result:
ok single line: 'Impossible'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
912357890016129
output:
444444444444444
result:
ok single line: '444444444444444 '
Test #21:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
189765003210110
output:
44444444444444
result:
ok single line: '44444444444444 '
Test #22:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
778899023235656
output:
1111111111111111
result:
ok single line: '1111111111111111 '
Test #23:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
5
output:
4 6
result:
ok single line: '4 6 '
Test #24:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
333301467899999
output:
255555555555555
result:
ok single line: '255555555555555 '
Test #25:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
433301467899999
output:
522222222222222
result:
ok single line: '522222222222222 '
Test #26:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
274613689526294
output:
0
result:
ok single line: '0 '
Test #27:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
340039250762387
output:
111111111111111
result:
ok single line: '111111111111111 '
Test #28:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
136418797906598
output:
222222222222222
result:
ok single line: '222222222222222 '
Test #29:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
161072428972852
output:
33333333333333
result:
ok single line: '33333333333333 '
Test #30:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
589602035803718
output:
444444444444444
result:
ok single line: '444444444444444 '
Test #31:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
146863487601092
output:
55555555555555
result:
ok single line: '55555555555555 '
Test #32:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
350039125347282
output:
66666666666666
result:
ok single line: '66666666666666 '
Test #33:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
652956153048838
output:
777777777777777
result:
ok single line: '777777777777777 '
Test #34:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
9
output:
8 10
result:
ok single line: '8 10 '
Test #35:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
421200497362543
output:
88888888888888
result:
ok single line: '88888888888888 '
Test #36:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
867410302085138
output:
999999999999999
result:
ok single line: '999999999999999 '
Test #37:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
223344556677889
output:
111111111111111
result:
ok single line: '111111111111111 '
Test #38:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
110044556677889
output:
33333333333333
result:
ok single line: '33333333333333 '
Test #39:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
110022336677889
output:
55555555555555
result:
ok single line: '55555555555555 '
Test #40:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
110022334455889
output:
77777777777777
result:
ok single line: '77777777777777 '
Test #41:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
110022334455667
output:
99999999999999
result:
ok single line: '99999999999999 '
Test #42:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
442233116677889
output:
500000000000000
result:
ok single line: '500000000000000 '
Test #43:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
220033445577889
output:
166666666666666
result:
ok single line: '166666666666666 '
Test #44:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
330011445566889
output:
277777777777777
result:
ok single line: '277777777777777 '
Test #45:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
10
output:
9
result:
ok single line: '9 '
Test #46:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
770022445566119
output:
833333333333333
result:
ok single line: '833333333333333 '
Test #47:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
550022331166778
output:
499999999999999
result:
ok single line: '499999999999999 '
Test #48:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
94
output:
88 100
result:
ok single line: '88 100 '
Test #49:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
394
output:
288 500
result:
ok single line: '288 500 '
Test #50:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
944
output:
888 1000
result:
ok single line: '888 1000 '
Test #51:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
999
output:
1000
result:
ok single line: '1000 '
Test #52:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
123456789
output:
0
result:
ok single line: '0 '