|
| 1 | +#include <vector> |
| 2 | +#include <list> |
| 3 | +#include <map> |
| 4 | +#include <set> |
| 5 | +#include <queue> |
| 6 | +#include <deque> |
| 7 | +#include <stack> |
| 8 | +#include <bitset> |
| 9 | +#include <algorithm> |
| 10 | +#include <functional> |
| 11 | +#include <numeric> |
| 12 | +#include <utility> |
| 13 | +#include <sstream> |
| 14 | +#include <iostream> |
| 15 | +#include <iomanip> |
| 16 | +#include <cstdio> |
| 17 | +#include <cmath> |
| 18 | +#include <cstdlib> |
| 19 | +#include <ctime> |
| 20 | + |
| 21 | +using namespace std; |
| 22 | + |
| 23 | +const int MAXN = 500; |
| 24 | +int min_p[MAXN]; |
| 25 | +int sum_d[MAXN]; |
| 26 | +#define pii pair<int, int> |
| 27 | +const int INF = 2100000000; |
| 28 | + |
| 29 | +class BallsSeparating { |
| 30 | + public: |
| 31 | + int get_sum(int a, int b, int c, vector<int> red, vector<int> green, vector<int> blue, int sz){ |
| 32 | + int tmp=0; |
| 33 | + for(int i=0; i<sz; i++){ |
| 34 | + if(i==a || i==b||i==c)continue; |
| 35 | + tmp += min_p[i]; |
| 36 | + } |
| 37 | + return tmp; |
| 38 | + } |
| 39 | + |
| 40 | + int minOperations(vector <int> red, vector <int> green, vector <int> blue) { |
| 41 | + |
| 42 | + int sz = red.size(); |
| 43 | + if(sz<3){ |
| 44 | + return -1; |
| 45 | + } |
| 46 | + |
| 47 | + vector< pii > sorted_d; |
| 48 | + for(int i=0; i<sz; i++){ |
| 49 | + int tmp = 0; |
| 50 | + min_p[i] = min(min( red[i]+green[i], red[i]+blue[i]), blue[i] + green[i]); |
| 51 | + } |
| 52 | + |
| 53 | + int final_answer = INF; |
| 54 | + for(int i=0; i<sz; i++){ |
| 55 | + for(int j=0; j<sz; j++){ |
| 56 | + for(int k=0; k<sz; k++){ |
| 57 | + if(i==j || j==k || i==k)continue; |
| 58 | + cout<<i<<" "<<j<<" "<<k <<endl; |
| 59 | + int tmp_ans = green[i] + blue[i] + red[j] + blue[j] + red[k] + green[k]+ get_sum(i, j, k, red, green, blue, sz); |
| 60 | + final_answer = min(tmp_ans, final_answer); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + return final_answer; |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + return 0; |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +// BEGIN KAWIGIEDIT TESTING |
| 74 | +// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof |
| 75 | +bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <int> p1, vector <int> p2, bool hasAnswer, int p3) { |
| 76 | + cout << "Test " << testNum << ": [" << "{"; |
| 77 | + for (int i = 0; int(p0.size()) > i; ++i) { |
| 78 | + if (i > 0) { |
| 79 | + cout << ","; |
| 80 | + } |
| 81 | + cout << p0[i]; |
| 82 | + } |
| 83 | + cout << "}" << "," << "{"; |
| 84 | + for (int i = 0; int(p1.size()) > i; ++i) { |
| 85 | + if (i > 0) { |
| 86 | + cout << ","; |
| 87 | + } |
| 88 | + cout << p1[i]; |
| 89 | + } |
| 90 | + cout << "}" << "," << "{"; |
| 91 | + for (int i = 0; int(p2.size()) > i; ++i) { |
| 92 | + if (i > 0) { |
| 93 | + cout << ","; |
| 94 | + } |
| 95 | + cout << p2[i]; |
| 96 | + } |
| 97 | + cout << "}"; |
| 98 | + cout << "]" << endl; |
| 99 | + BallsSeparating *obj; |
| 100 | + int answer; |
| 101 | + obj = new BallsSeparating(); |
| 102 | + clock_t startTime = clock(); |
| 103 | + answer = obj->minOperations(p0, p1, p2); |
| 104 | + clock_t endTime = clock(); |
| 105 | + delete obj; |
| 106 | + bool res; |
| 107 | + res = true; |
| 108 | + cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl; |
| 109 | + if (hasAnswer) { |
| 110 | + cout << "Desired answer:" << endl; |
| 111 | + cout << "\t" << p3 << endl; |
| 112 | + } |
| 113 | + cout << "Your answer:" << endl; |
| 114 | + cout << "\t" << answer << endl; |
| 115 | + if (hasAnswer) { |
| 116 | + res = answer == p3; |
| 117 | + } |
| 118 | + if (!res) { |
| 119 | + cout << "DOESN'T MATCH!!!!" << endl; |
| 120 | + } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) { |
| 121 | + cout << "FAIL the timeout" << endl; |
| 122 | + res = false; |
| 123 | + } else if (hasAnswer) { |
| 124 | + cout << "Match :-)" << endl; |
| 125 | + } else { |
| 126 | + cout << "OK, but is it right?" << endl; |
| 127 | + } |
| 128 | + cout << "" << endl; |
| 129 | + return res; |
| 130 | +} |
| 131 | +int main() { |
| 132 | + bool all_right; |
| 133 | + all_right = true; |
| 134 | + |
| 135 | + vector <int> p0; |
| 136 | + vector <int> p1; |
| 137 | + vector <int> p2; |
| 138 | + int p3; |
| 139 | + |
| 140 | + { |
| 141 | + // ----- test 0 ----- |
| 142 | + int t0[] = {1,1,1}; |
| 143 | + p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0])); |
| 144 | + int t1[] = {1,1,1}; |
| 145 | + p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0])); |
| 146 | + int t2[] = {1,1,1}; |
| 147 | + p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0])); |
| 148 | + p3 = 6; |
| 149 | + all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right; |
| 150 | + // ------------------ |
| 151 | + } |
| 152 | + |
| 153 | + { |
| 154 | + // ----- test 1 ----- |
| 155 | + int t0[] = {5}; |
| 156 | + p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0])); |
| 157 | + int t1[] = {6}; |
| 158 | + p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0])); |
| 159 | + int t2[] = {8}; |
| 160 | + p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0])); |
| 161 | + p3 = -1; |
| 162 | + all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right; |
| 163 | + // ------------------ |
| 164 | + } |
| 165 | + |
| 166 | + { |
| 167 | + // ----- test 2 ----- |
| 168 | + int t0[] = {4,6,5,7}; |
| 169 | + p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0])); |
| 170 | + int t1[] = {7,4,6,3}; |
| 171 | + p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0])); |
| 172 | + int t2[] = {6,5,3,8}; |
| 173 | + p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0])); |
| 174 | + p3 = 37; |
| 175 | + all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right; |
| 176 | + // ------------------ |
| 177 | + } |
| 178 | + |
| 179 | + { |
| 180 | + // ----- test 3 ----- |
| 181 | + int t0[] = {7,12,9,9,7}; |
| 182 | + p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0])); |
| 183 | + int t1[] = {7,10,8,8,9}; |
| 184 | + p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0])); |
| 185 | + int t2[] = {8,9,5,6,13}; |
| 186 | + p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0])); |
| 187 | + p3 = 77; |
| 188 | + all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right; |
| 189 | + // ------------------ |
| 190 | + } |
| 191 | + |
| 192 | + { |
| 193 | + // ----- test 4 ----- |
| 194 | + int t0[] = {842398,491273,958925,849859,771363,67803,184892,391907,256150,75799}; |
| 195 | + p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0])); |
| 196 | + int t1[] = {268944,342402,894352,228640,903885,908656,414271,292588,852057,889141}; |
| 197 | + p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0])); |
| 198 | + int t2[] = {662939,340220,600081,390298,376707,372199,435097,40266,145590,505103}; |
| 199 | + p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0])); |
| 200 | + p3 = 7230607; |
| 201 | + all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right; |
| 202 | + // ------------------ |
| 203 | + } |
| 204 | + |
| 205 | + if (all_right) { |
| 206 | + cout << "You're a stud (at least on the example cases)!" << endl; |
| 207 | + } else { |
| 208 | + cout << "Some of the test cases had errors." << endl; |
| 209 | + } |
| 210 | + return 0; |
| 211 | +} |
| 212 | +// END KAWIGIEDIT TESTING |
0 commit comments