-
Notifications
You must be signed in to change notification settings - Fork 13
/
leetcode1.cpp
302 lines (280 loc) · 9.02 KB
/
leetcode1.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#pragma GCC optimize("O3", "unroll-loops")
// God Help me !!
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(20)
#define RANDOM srand(time(nullptr))
#define sz(a) (int)a.size()
#define CLR(d) memset(d, 0, sizeof(d))
#define ll long long
#define ld long double
#define ui unsigned int
#define ull unsigned ll
#define graph vector<vector<int>>
#define V vector
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef V<double> vd;
typedef V<pii> vpii;
typedef V<pll> vpll;
typedef pair<int,pii> piii;
typedef priority_queue<pii, vector<pii>, greater<pii> > pqq;
#define shuffle(a) \
for (int i = -sz(a); i < sz(a); ++i) \
swap(a[rand() % sz(a)], a[rand() % sz(a)])
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define sep(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define hashmap unordered_map
#define hashset unordered_set
#define lb lower_bound
#define ub upper_bound
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define endl "\n"
#define n6 3000005
#define n7 30000005
#define n8 300000005
#define n3 3005
#define n5 300005
#define lbpos(v,x) (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB
#define ubpos(v,x) (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB
/*******************************************************************************//*******************************************************************************/
#define dbg1(x) cout << #x << ": " << x << endl;
#define dbg2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl;
#define dbg3(x, y, z) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define dbg4(a, b, c, d) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define dbg5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define dbg6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define dbgv(x) cout << #x << " = " << x << endl
#define dbga(arr, len) {cout << #arr << " = "; for (int _ = 0; _ < len; _++)cout << arr[_] << " "; cout << endl;}
#define dbgi(it) {cout << #it << " = "; for (const auto& _ : it)cout << _ << " "; cout << endl;}
/*******************************************************************************//*******************************************************************************/
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline void amin(T &x, U y) { if (x > y) x = y; }
template<class T, class U> inline void amax(T &x, U y) { if (x < y) x = y; }
/*******************************************************************************//*******************************************************************************/
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " =: " << a << endl;
err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
bool first = true;
os << "[";
for(unsigned int i = 0; i < v.size(); i++) {
if(!first) os << ", ";
os << v[i];
first = false;
}
return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::set<T>& v) {
bool first = true;
os << "{";
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if(!first) os << ", ";
os << *ii;
first = false;
}
return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
bool first = true;
os << "{";
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if(!first) os << ", ";
os << *ii ;
first = false;
}
return os << "}";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
os << '\n';
for (auto &u: v) os << u << '\n';
return os;
}
/*******************************************************************************//*******************************************************************************/
template <size_t r, size_t c>
void printmatrix(int (&arr)[r][c], int r1, int c1)
{
for (size_t i = 1; i <= r1; i++)
{
for (size_t j = 1; j <= c1; j++){
cout<<arr[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n***********\n";
}
void showdq(deque <int> g)
{
for (auto it = g.begin(); it != g.end(); ++it)
cout << *it << ' ' ;
cout << '\n';
}
void showstack(stack <int> s)
{
while(!s.empty()){
cout << s.top() << ' ';
s.pop();
}
cout << '\n';
}
void showqueue(queue<int> q)
{
while(!q.empty()){
cout << q.front() << ' ';
q.pop();
}
cout << '\n';
}
void showpq(priority_queue <int> gq)
{
priority_queue <int> g = gq;
while (!g.empty())
{
cout << '\t' << g.top();
g.pop();
}
cout << '\n';
}
/*******************************************************************************//*******************************************************************************/
const int mod = 1e9 + 7;
const double eps = 1e-9;
#define inf 1000000000000000007ll
#define intinf ((1 << 31) - 1)
/*******************************************************************************//*******************************************************************************/
inline ll add(ll a, ll b) {
a += b;
if (a >= mod) a -= mod;
return a;
}
inline ll sub(ll a, ll b) {
a -= b;
if (a < 0) a += mod;
return a;
}
inline ll mul(ll a, ll b) {
return (long long) a * b % mod;
}
inline ll power(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
/*******************************************************************************//*******************************************************************************/
// sort(vp.begin(), vp.end(), [](auto &l, auto &r){
// if(l.second!=r.second)
// return l.second > r.second;
// return l.first < r.first;
// });
// > descend
// < ascend
int calc(int n){
int count =0;
while(n>0){
n = n&(n-1);
count+=1;
}
return count;
}
// int bin[n6];
// void pre(){
// rep(i,0,n6-2){
// bin[i] = calc(i);
// }
// }
int solve(int x){
int s =0;
while(x){
int rem = x%10;
s = s * 10 + rem;
x/=10;
}
return s;
}
class Solution {
public:
// void numsSameConsecDiff(int n, int k) {
vector<int> numsSameConsecDiff(int n, int k) {
vi vv;
vi ans;
rep(i,0,10){
if(i+k<=9){
vv.pb(i);
}
}
for(auto &it: vv){
string s = "";
if(it==0){
rep(i,1,n){
if(i&1)
s+=it+k;
else
s+='0';
}
dbgv(s);
// ans.pb(stoi(s));
}
else{
rep(i,1,n){
if(i&1)
s+=it+k;
else
s+='0';
}
dbgv(s);
// ans.pb(stoi(s));
s = "";
rep(i,1,n){
if(i&1)
s+='0';
else
s+=it+k;
}
dbgv(s);
// ans.pb(stoi(s));
}
}
// dbgi(ans);
return ans;
}
};
signed main(){
Solution sol;
cout<<sol.numsSameConsecDiff(3,7);
}