Skip to content

Commit edfd434

Browse files
author
esulaimanov
committed
another srm
1 parent 4c7c5ab commit edfd434

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(topcoder)
3-
add_executable(topcoder OverallScores.cpp)
3+
add_executable(topcoder DivideLoot.cpp)
44
ADD_DEFINITIONS(-std=c++11)

DivideLoot.cpp

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
24+
class DivideLoot {
25+
public:
26+
string verify(int N, vector <int> loot) {
27+
int sum = accumulate(loot.begin(),loot.end(),0);
28+
if (sum % N != 0){
29+
return "impossible";
30+
}
31+
int d = sum / N;
32+
33+
multiset<int> m(loot.begin(),loot.end());
34+
35+
while (m.count(d)){
36+
m.erase(d);
37+
}
38+
39+
for (int i = 1; i <= d; ++i) {
40+
while (m.count(i) && m.count(d - i)){
41+
m.erase(i);
42+
m.erase(d - i);
43+
}
44+
}
45+
if (m.empty()){
46+
return "possible";
47+
}
48+
return "impossible";
49+
}
50+
};
51+
52+
53+
// BEGIN KAWIGIEDIT TESTING
54+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
55+
bool KawigiEdit_RunTest(int testNum, int p0, vector <int> p1, bool hasAnswer, string p2) {
56+
cout << "Test " << testNum << ": [" << p0 << "," << "{";
57+
for (int i = 0; int(p1.size()) > i; ++i) {
58+
if (i > 0) {
59+
cout << ",";
60+
}
61+
cout << p1[i];
62+
}
63+
cout << "}";
64+
cout << "]" << endl;
65+
DivideLoot *obj;
66+
string answer;
67+
obj = new DivideLoot();
68+
clock_t startTime = clock();
69+
answer = obj->verify(p0, p1);
70+
clock_t endTime = clock();
71+
delete obj;
72+
bool res;
73+
res = true;
74+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
75+
if (hasAnswer) {
76+
cout << "Desired answer:" << endl;
77+
cout << "\t" << "\"" << p2 << "\"" << endl;
78+
}
79+
cout << "Your answer:" << endl;
80+
cout << "\t" << "\"" << answer << "\"" << endl;
81+
if (hasAnswer) {
82+
res = answer == p2;
83+
}
84+
if (!res) {
85+
cout << "DOESN'T MATCH!!!!" << endl;
86+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
87+
cout << "FAIL the timeout" << endl;
88+
res = false;
89+
} else if (hasAnswer) {
90+
cout << "Match :-)" << endl;
91+
} else {
92+
cout << "OK, but is it right?" << endl;
93+
}
94+
cout << "" << endl;
95+
return res;
96+
}
97+
int main() {
98+
bool all_right;
99+
all_right = true;
100+
101+
int p0;
102+
vector <int> p1;
103+
string p2;
104+
105+
{
106+
// ----- test 0 -----
107+
p0 = 1;
108+
int t1[] = {47};
109+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
110+
p2 = "possible";
111+
all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
112+
// ------------------
113+
}
114+
115+
{
116+
// ----- test 1 -----
117+
p0 = 3;
118+
int t1[] = {10,8,10,1,1};
119+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
120+
p2 = "impossible";
121+
all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
122+
// ------------------
123+
}
124+
125+
{
126+
// ----- test 2 -----
127+
p0 = 3;
128+
int t1[] = {3,9,10,7,1};
129+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
130+
p2 = "possible";
131+
all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
132+
// ------------------
133+
}
134+
135+
{
136+
// ----- test 3 -----
137+
p0 = 6;
138+
int t1[] = {1,1,1,2,1,1,1,1,1,1,1};
139+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
140+
p2 = "possible";
141+
all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
142+
// ------------------
143+
}
144+
145+
{
146+
// ----- test 4 -----
147+
p0 = 2;
148+
int t1[] = {40,1,42};
149+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
150+
p2 = "impossible";
151+
all_right = KawigiEdit_RunTest(4, p0, p1, true, p2) && all_right;
152+
// ------------------
153+
}
154+
155+
if (all_right) {
156+
cout << "You're a stud (at least on the example cases)!" << endl;
157+
} else {
158+
cout << "Some of the test cases had errors." << endl;
159+
}
160+
return 0;
161+
}
162+
// END KAWIGIEDIT TESTING
163+
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!

0 commit comments

Comments
 (0)