-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path4001.cpp
62 lines (51 loc) · 1.22 KB
/
4001.cpp
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
/**
* @file 4001.cpp
* @author Macesuted ([email protected])
* @date 2023-12-24
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif
bool mem1;
#define maxn 3005
string s[maxn], l[maxn], r[maxn];
multiset<string> S;
queue<int> fnd[256];
void solve(void) {
int n, m;
cin >> n >> m;
string M1, M2;
M1 = M2 = string(1, 'z' + 1);
for (int i = 1; i <= n; i++) {
cin >> s[i], l[i] = r[i] = s[i];
sort(r[i].begin(), r[i].end(), greater<char>()), l[i] = r[i], reverse(l[i].begin(), l[i].end());
if (M1 > r[i])
M2 = M1, M1 = r[i];
else if (M2 > r[i])
M2 = r[i];
}
for (int i = 1; i <= n; i++) cout << (l[i] < (M1 == r[i] ? M2 : M1));
cout << endl;
return;
}
bool mem2;
int main() {
#ifndef LOCAL
freopen("dict.in", "r", stdin), freopen("dict.out", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif
int _ = 1;
while (_--) solve();
#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}