1def organize(cars, students):
2
3 from itertools import permutations
4
5 if cars.len()*4 < students.len():
6 return False
7
8 seats = {}
9 blacklist_students = dict.fromkeys(students, [])
10 blacklist_cars = dict.fromkeys(students, [])
11
12 for car in cars:
13 for stud in students:
14 car.add_student(stud)
15 if not stud.is_comfy():
16 blacklist_cars[stud].append(car)
17
18 for stud in students:
19 for other in students:
20 if stud != other:
21 for car in cars:
22 if not car in blacklist_cars[stud] and not car in blacklist_cars[other]:
23 car.add_student(stud)
24 car.add_student(other)
25 if not stud.is_comfy() or not other.is_comfy():
26 blacklist_students[stud].append(other)
27 blacklist_students[other].append(stud)
28
29 car_has = dict.fromkeys(cars, [])
30 for perm in list(permutations(cars)):
31 flag_no_problems = True
32 for student in students:
33 flag_not_in_car = True
34 for car in perm:
35 if car_has[car].len() < 4 and not car in blacklist_cars[student]:
36 flag_has_bad_companions = False
37 for insiders in car:
38 if insiders in blacklist_students[student]:
39 flag_has_bad_companions = True
40 if flag_has_bad_companions:
41 continue
42 car.add_student(student)
43 car_has[car].append(student)
44 flag_not_in_car = False
45 break
46 if flag_not_in_car:
47 flag_no_problems = False
48 if flag_no_problems:
49 return True
50 return False
51
EEEEE
======================================================================
ERROR: test_big_input (test.TesFull)
Test a big case to ensure no huge bruteforcing.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 90, in test_big_input
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 7, in organize
if cars.len()*4 < students.len():
AttributeError: 'list' object has no attribute 'len'
======================================================================
ERROR: test_empty (test.TesFull)
Test with empty cars.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 27, in test_empty
anti_rusalov_false(self, organize([], students))
File "/tmp/solution.py", line 7, in organize
if cars.len()*4 < students.len():
AttributeError: 'list' object has no attribute 'len'
======================================================================
ERROR: test_real_case_false (test.TesFull)
Test a real case for False.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 36, in test_real_case_false
anti_rusalov_false(self, organize(cars, students))
File "/tmp/solution.py", line 7, in organize
if cars.len()*4 < students.len():
AttributeError: 'list' object has no attribute 'len'
======================================================================
ERROR: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 47, in test_regular_case
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 7, in organize
if cars.len()*4 < students.len():
AttributeError: 'list' object has no attribute 'len'
======================================================================
ERROR: test_single_solution_case (test.TesFull)
Test a single-solution case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 65, in test_single_solution_case
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 7, in organize
if cars.len()*4 < students.len():
AttributeError: 'list' object has no attribute 'len'
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (errors=5)
n | 1 | from itertools import permutations | n | 1 | |
2 | 2 | ||||
3 | def organize(cars, students): | 3 | def organize(cars, students): | ||
t | t | 4 | |||
5 | from itertools import permutations | ||||
6 | |||||
4 | if cars.len()*4 < students.len(): | 7 | if cars.len()*4 < students.len(): | ||
5 | return False | 8 | return False | ||
6 | 9 | ||||
7 | seats = {} | 10 | seats = {} | ||
8 | blacklist_students = dict.fromkeys(students, []) | 11 | blacklist_students = dict.fromkeys(students, []) | ||
9 | blacklist_cars = dict.fromkeys(students, []) | 12 | blacklist_cars = dict.fromkeys(students, []) | ||
10 | 13 | ||||
11 | for car in cars: | 14 | for car in cars: | ||
12 | for stud in students: | 15 | for stud in students: | ||
13 | car.add_student(stud) | 16 | car.add_student(stud) | ||
14 | if not stud.is_comfy(): | 17 | if not stud.is_comfy(): | ||
15 | blacklist_cars[stud].append(car) | 18 | blacklist_cars[stud].append(car) | ||
16 | 19 | ||||
17 | for stud in students: | 20 | for stud in students: | ||
18 | for other in students: | 21 | for other in students: | ||
19 | if stud != other: | 22 | if stud != other: | ||
20 | for car in cars: | 23 | for car in cars: | ||
21 | if not car in blacklist_cars[stud] and not car in blacklist_cars[other]: | 24 | if not car in blacklist_cars[stud] and not car in blacklist_cars[other]: | ||
22 | car.add_student(stud) | 25 | car.add_student(stud) | ||
23 | car.add_student(other) | 26 | car.add_student(other) | ||
24 | if not stud.is_comfy() or not other.is_comfy(): | 27 | if not stud.is_comfy() or not other.is_comfy(): | ||
25 | blacklist_students[stud].append(other) | 28 | blacklist_students[stud].append(other) | ||
26 | blacklist_students[other].append(stud) | 29 | blacklist_students[other].append(stud) | ||
27 | 30 | ||||
28 | car_has = dict.fromkeys(cars, []) | 31 | car_has = dict.fromkeys(cars, []) | ||
29 | for perm in list(permutations(cars)): | 32 | for perm in list(permutations(cars)): | ||
30 | flag_no_problems = True | 33 | flag_no_problems = True | ||
31 | for student in students: | 34 | for student in students: | ||
32 | flag_not_in_car = True | 35 | flag_not_in_car = True | ||
33 | for car in perm: | 36 | for car in perm: | ||
34 | if car_has[car].len() < 4 and not car in blacklist_cars[student]: | 37 | if car_has[car].len() < 4 and not car in blacklist_cars[student]: | ||
35 | flag_has_bad_companions = False | 38 | flag_has_bad_companions = False | ||
36 | for insiders in car: | 39 | for insiders in car: | ||
37 | if insiders in blacklist_students[student]: | 40 | if insiders in blacklist_students[student]: | ||
38 | flag_has_bad_companions = True | 41 | flag_has_bad_companions = True | ||
39 | if flag_has_bad_companions: | 42 | if flag_has_bad_companions: | ||
40 | continue | 43 | continue | ||
41 | car.add_student(student) | 44 | car.add_student(student) | ||
42 | car_has[car].append(student) | 45 | car_has[car].append(student) | ||
43 | flag_not_in_car = False | 46 | flag_not_in_car = False | ||
44 | break | 47 | break | ||
45 | if flag_not_in_car: | 48 | if flag_not_in_car: | ||
46 | flag_no_problems = False | 49 | flag_no_problems = False | ||
47 | if flag_no_problems: | 50 | if flag_no_problems: | ||
48 | return True | 51 | return True | ||
49 | return False | 52 | return False | ||
50 | 53 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|