-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2529.cpp
More file actions
114 lines (93 loc) · 2.25 KB
/
2529.cpp
File metadata and controls
114 lines (93 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <string>
using namespace std;
string arr;
int N;
long long minV = 12345678911;
long long maxV = 0;
long long change(string a) {
long long sum = 0;
for (int i = 0; i < a.size(); i++) {
sum *= 10;
sum = sum + (a[i] - '0');
}
return sum;
}
string revChange(long long a) {
string temp;
temp = to_string(a);
if (temp.size() == N) {
string temp2;
temp2 += "0";
temp2 += temp;
return temp2;
}
else {
return temp;
}
}
void sub(string a) {
if (a.size() == N + 1) {
long long val = change(a);
if (val > maxV)
maxV = val;
if (val < minV)minV = val;
return;
}
if (a.size() == 0) {
for (int i = 0; i < 10; i++) {
string temp = a;
temp += (i + '0');
sub(temp);
}
}
else {
int visited[10] = {};
for (int i = 0; i < a.size(); i++) {
visited[(a[i] - '0')] = 1;
}
for (int i = 0; i < 10; i++) {
if (visited[i] == 1)continue;
int idx = a.size() - 1;
if (idx == -1)idx = 0;
int prev = (a[idx] - '0');
char cmp = arr[idx];
if (cmp == '>') {
if (prev > i) {
visited[i] = 1;
string temp = a;
temp += (i + '0');
sub(temp);
visited[i] = 0;
}
}
else {
if (prev < i) {
visited[i] = 1;
string temp = a;
temp += (i + '0');
sub(temp);
visited[i] = 0;
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
for (int i = 0; i < N; i++) {
char temp;
cin >> temp;
arr += temp;
}
string temp = "";
sub(temp);
cout << revChange(maxV) << '\n';
cout << revChange(minV) << '\n';
}