└── 2037 ├── a.py ├── b.py └── b.cpp /2037/a.py: -------------------------------------------------------------------------------- 1 | def solve(a_array): 2 | a_dict = {} 3 | for a in a_array: 4 | a_dict[a] = a_dict.get(a, 0) + 1 5 | 6 | max_score = 0 7 | for a in a_dict: 8 | max_score += a_dict[a] // 2 9 | 10 | return max_score 11 | 12 | count = int(input()) 13 | 14 | for i in range(count): 15 | input() 16 | a_array = list(map(int, input().split())) 17 | print(solve(a_array)) -------------------------------------------------------------------------------- /2037/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | def solve(length, mixed_grids): 4 | k = length - 2 5 | counts = Counter(mixed_grids) 6 | mixed_grids_set = set(mixed_grids) 7 | 8 | for a in range(1, int(k ** 0.5) + 1): 9 | if k % a == 0: 10 | b = k // a 11 | if a in mixed_grids_set and b in mixed_grids_set: 12 | if a == b and counts[a] < 2: 13 | continue 14 | return f"{a} {b}" 15 | 16 | 17 | count = int(input()) 18 | 19 | for i in range(count): 20 | length = int(input()) 21 | mixed_grids = list(map(int, input().split())) 22 | print(solve(length, mixed_grids)) -------------------------------------------------------------------------------- /2037/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | pair solve(int length, const vector& mixed_grids) { 10 | int k = length - 2; 11 | unordered_map counts; 12 | unordered_set mixed_grids_set; 13 | 14 | for (int num : mixed_grids) { 15 | counts[num]++; 16 | mixed_grids_set.insert(num); 17 | } 18 | 19 | for (int a = 1; a <= sqrt(k); ++a) { 20 | if (k % a == 0) { 21 | int b = k / a; 22 | if (mixed_grids_set.count(a) && mixed_grids_set.count(b)) { 23 | if (a == b && counts[a] < 2) { 24 | continue; 25 | } 26 | return {a, b}; 27 | } 28 | } 29 | } 30 | return {-1, -1}; 31 | } 32 | 33 | int main() { 34 | int count; 35 | cin >> count; 36 | 37 | for (int i = 0; i < count; ++i) { 38 | int length; 39 | cin >> length; 40 | vector mixed_grids(length); 41 | for (int j = 0; j < length; ++j) { 42 | cin >> mixed_grids[j]; 43 | } 44 | pair result = solve(length, mixed_grids); 45 | if (result.first != -1) { 46 | cout << result.first << " " << result.second << endl; 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | --------------------------------------------------------------------------------