-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasas.cpp
More file actions
55 lines (48 loc) · 1.22 KB
/
masas.cpp
File metadata and controls
55 lines (48 loc) · 1.22 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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
vector<long long int> sol(int n, int a, int b){
long long int res = 0;
vector<long long int> ans;
ans.push_back(0);
for(int i = 0; i < n-1; i++){
vector<long long int> ans2;
unordered_map<long long int, long long int> an;
for(int j = 0; j < ans.size(); j++){
if(an.find(ans[j]+a) == an.end()){
ans2.push_back(ans[j]+a);
an[ans[j]+a] = 1;
}
if(an.find(ans[j]+b) == an.end()){
ans2.push_back(ans[j]+b);
an[ans[j]+b] = 1;
}
}
ans = ans2;
}
return ans;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t = 0;
int n = 0;
int a = 0;
int b = 0;
cin >>t;
for(int i = 0; i < t; i++){
cin >>n;
cin >>a;
cin >>b;
vector<long long int> ans = sol(n, a,b);
sort(ans.begin(), ans.end());
for(int elements: ans){
cout<< elements <<" ";
}
cout << endl;
}
return 0;
}