-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Another_Sorting_Problem.cpp
More file actions
151 lines (138 loc) · 3.71 KB
/
A_Another_Sorting_Problem.cpp
File metadata and controls
151 lines (138 loc) · 3.71 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set
#define ull unsigned long long int
#define int long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
const long double PI = 3.141592653589793238462643383279502884197169399;
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res.push_back(static_cast<char>('0' + v[i]));
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif
// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))
const int mod = 1e9 + 7;
bool cmp(pair<string,int> x, pair<string,int> y){
string a = x.F,b=y.F;
int sz = (int)a.size();
for(int i=0; i<sz; i++){
if(a[i] != b[i]){
if(i%2==0){
if(a[i] > b[i]) return 0;
else return 1;
}
else {
if(a[i] > b[i]) return 1;
else return 0;
}
}
}
return 1;
}
/*
greater<int> -> bool (int a,int b){
a > b return 1;
else return 0;
}
*/
/*
cmp -> 0 -> b < a
1 -> a < b
*/
void solve(){
int n,m;
cin >> n >> m;
vector<pair<string,int>> a(n);
for(int i=0; i<n; i++){
cin >> a[i].F;
a[i].S=i;
}
sort(a.begin(),a.end(),cmp);
for(int i=0; i<n; i++){
cout << a[i].S+1 << ' ';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int tt=1;
//cin >> tt;
while(tt--){
solve();
}
}