Submission #73061281
Source Code Expand
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <map>
using namespace std;
vector<long long> get_divisors(long long s) {
vector<long long> divisors;
if (s == 0) return divisors;
map<long long, int> factors;
for (long long i = 2; i * i <= s; ++i) {
while (s % i == 0) {
factors[i]++;
s /= i;
}
}
if (s > 1) {
factors[s]++;
}
divisors.push_back(1);
for (auto& p : factors) {
long long prime = p.first;
int exp = p.second;
int sz = divisors.size();
long long current = 1;
for (int e = 1; e <= exp; ++e) {
current *= prime;
for (int j = 0; j < sz; ++j) {
divisors.push_back(divisors[j] * current);
}
}
}
sort(divisors.begin(), divisors.end());
auto last = unique(divisors.begin(), divisors.end());
divisors.erase(last, divisors.end());
return divisors;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<long long> A(N);
long long sum_S = 0;
long long max_A = 0;
unordered_map<long long, int> cnt_map;
for (int i = 0; i < N; ++i) {
cin >> A[i];
sum_S += A[i];
if (A[i] > max_A) {
max_A = A[i];
}
cnt_map[A[i]]++;
}
vector<long long> divisors = get_divisors(sum_S);
vector<long long> ans;
for (long long L : divisors) {
if (L < max_A) {
continue;
}
long long K = sum_S / L;
if (K < (N + 1) / 2 || K > N) {
continue;
}
int required = 2 * K - N;
int actual = cnt_map.count(L) ? cnt_map[L] : 0;
if (actual == required) {
ans.push_back(L);
}
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); ++i) {
if (i > 0) {
cout << " ";
}
cout << ans[i];
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - AtCoder Riko |
| User | xuhanjin |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 2091 Byte |
| Status | AC |
| Exec Time | 49 ms |
| Memory | 17768 KiB |
Compile Error
./Main.cpp: In function 'int main()':
./Main.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < ans.size(); ++i) {
| ~~^~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt |
| All | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt, 1_1.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 2_1.txt, 2_2.txt, 2_3.txt, 2_4.txt, 3_1.txt, 3_2.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 4_1.txt, 4_2.txt, 4_3.txt, 4_4.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 0_sample_1.txt | AC | 1 ms | 3644 KiB |
| 0_sample_2.txt | AC | 1 ms | 3388 KiB |
| 0_sample_3.txt | AC | 1 ms | 3576 KiB |
| 1_1.txt | AC | 37 ms | 14988 KiB |
| 1_2.txt | AC | 36 ms | 15168 KiB |
| 1_3.txt | AC | 37 ms | 15020 KiB |
| 1_4.txt | AC | 36 ms | 15044 KiB |
| 1_5.txt | AC | 37 ms | 15112 KiB |
| 2_1.txt | AC | 49 ms | 17744 KiB |
| 2_2.txt | AC | 48 ms | 17740 KiB |
| 2_3.txt | AC | 47 ms | 17688 KiB |
| 2_4.txt | AC | 48 ms | 17768 KiB |
| 3_1.txt | AC | 34 ms | 11728 KiB |
| 3_2.txt | AC | 24 ms | 7904 KiB |
| 3_3.txt | AC | 16 ms | 6116 KiB |
| 3_4.txt | AC | 13 ms | 5688 KiB |
| 3_5.txt | AC | 1 ms | 3460 KiB |
| 3_6.txt | AC | 14 ms | 5688 KiB |
| 4_1.txt | AC | 8 ms | 5612 KiB |
| 4_2.txt | AC | 13 ms | 5676 KiB |
| 4_3.txt | AC | 1 ms | 3576 KiB |
| 4_4.txt | AC | 1 ms | 3592 KiB |