-
Notifications
You must be signed in to change notification settings - Fork 5
/
DivisibleSetDiv1.cpp
156 lines (122 loc) · 3.65 KB
/
DivisibleSetDiv1.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
// BEGIN CUT HERE
/*
SRM 697 Div1 Easy (300)
問題
-N個の正の整数からなる配列bが与えられる
-以下の条件を全て満たす配列aが存在するかどうかを求める
-aの要素a[0],a[1],...a[N-1]は全て異なる
-各要素は1以上の整数
-a[i]^b[i]は、a[i]以外の全てのaの要素の積で割り切れる
*/
// END CUT HERE
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <iostream>
#include <sstream>
#include <cstring>
using namespace std;
typedef vector<int> IntVec;
class DivisibleSetDiv1 {
bool possible(IntVec b) {
sort(b.rbegin(), b.rend());
IntVec a(b.size());
iota(a.begin(), a.end(), 1);
int sum = accumulate(a.begin(), a.end(), 0);
for (int t = 0; t < 1000000; ++t) {
bool ok = true;
for (int i = 0; i != a.size(); ++i) {
if ((a[i] * (b[i] + 1)) < sum) {
for (int j = i; j != a.size(); ++j) {
++a[j], ++sum;
}
ok = false;
}
if (ok) {
return true;
}
}
}
return false;
}
public:
string isPossible(vector <int> b) {
return possible(b) ? "Possible" : "Impossible";
}
// BEGIN CUT HERE
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
public:
void run_test(int Case) {
int n = 0;
// test_case_0
if ((Case == -1) || (Case == n)){
int Arr0[] = {2,1};
string Arg1 = "Possible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
// test_case_1
if ((Case == -1) || (Case == n)){
int Arr0[] = {1,1};
string Arg1 = "Impossible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
// test_case_2
if ((Case == -1) || (Case == n)){
int Arr0[] = {7, 7, 7};
string Arg1 = "Possible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
// test_case_3
if ((Case == -1) || (Case == n)){
int Arr0[] = {5,3,5,4,6,1,3,7,9,6,2,5,4,1,1,9,6,10,10,6,10,7,7,8};
string Arg1 = "Impossible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
if ((Case == -1) || (Case == n)) {
int Arr0[] = { 2,2,3 };
string Arg1 = "Possible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
if ((Case == -1) || (Case == n)) {
int Arr0[] = { 2,3,4,5 };
string Arg1 = "Possible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
if ((Case == -1) || (Case == n)) {
int Arr0[] = { 3,1,3 };
string Arg1 = "Impossible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
if ((Case == -1) || (Case == n)) {
int Arr0[] = { 1,2,5 };
string Arg1 = "Possible";
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
verify_case(n, Arg1, isPossible(Arg0));
}
n++;
}
// END CUT HERE
};
// BEGIN CUT HERE
int main() {
DivisibleSetDiv1 ___test;
___test.run_test(-1);
}
// END CUT HERE