#include <bits/stdc++.h>
using namespace std;
using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
template<typename... Args> // tuples
ostream& operator<<(ostream& os, tuple<Args...> t) {
apply([&](Args... args) { string dlm = "{"; ((os << dlm << args, dlm = ", "), ...); }, t);
return os << "}";
}
template<typename T, typename V> // pairs
ostream& operator<<(ostream& os, pair<T, V> p) { return os << "{" << p.f << ", " << p.s << "}"; }
template<class T, class = decltype(begin(declval<T>()))> // iterables
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& os, const T& v) {
string dlm = "{";
for (auto& i : v) os << dlm << i, dlm = ", ";
return os << "}";
}
template <typename T, typename... V>
void printer(string pfx, const char *names, T&& head, V&& ...tail) {
int i = 0;
while (names[i] && names[i] != ',') i++;
constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
if (is_str) cerr << " " << head;
else cerr << pfx, cerr.write(names, i) << " = " << head;
if constexpr (sizeof...(tail)) printer(is_str ? "" : ",", names + i + 1, tail...);
else cerr << endl;
}
#ifdef LOCAL
#define dbg(...) printer(to_string(__LINE__) + ": ", #__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif
/*
*/
main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vt<ll> a(n); F0R (i, n) cin >> a[i];
vt<ll> ans(n + 1);
ll mx = 1;
F0R (i, n) mx *= n;
F0R (msk, mx) {
vt<ll> nums(n);
int tmp = msk;
F0R (i, n) {
int g = tmp % n;
tmp /= n;
nums[g] = gcd(nums[g], a[i]);
}
ll sum = accumulate(all(nums), 0ll);
int groups = 0;
F0R (i, n) if (nums[i] > 0) groups++;
ans[groups] = max(ans[groups], sum);
}
FOR (i, 1, n + 1) cout << ans[i] << endl;
}
Compilation message
Main.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
344 KB |
Output is correct |
2 |
Correct |
63 ms |
432 KB |
Output is correct |
3 |
Correct |
59 ms |
344 KB |
Output is correct |
4 |
Correct |
71 ms |
348 KB |
Output is correct |
5 |
Correct |
65 ms |
344 KB |
Output is correct |
6 |
Correct |
61 ms |
344 KB |
Output is correct |
7 |
Correct |
78 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
344 KB |
Output is correct |
9 |
Correct |
67 ms |
432 KB |
Output is correct |
10 |
Correct |
67 ms |
344 KB |
Output is correct |
11 |
Correct |
66 ms |
348 KB |
Output is correct |
12 |
Correct |
62 ms |
344 KB |
Output is correct |
13 |
Correct |
65 ms |
348 KB |
Output is correct |
14 |
Correct |
68 ms |
344 KB |
Output is correct |
15 |
Correct |
64 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
344 KB |
Output is correct |
2 |
Correct |
63 ms |
432 KB |
Output is correct |
3 |
Correct |
59 ms |
344 KB |
Output is correct |
4 |
Correct |
71 ms |
348 KB |
Output is correct |
5 |
Correct |
65 ms |
344 KB |
Output is correct |
6 |
Correct |
61 ms |
344 KB |
Output is correct |
7 |
Correct |
78 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
344 KB |
Output is correct |
9 |
Correct |
67 ms |
432 KB |
Output is correct |
10 |
Correct |
67 ms |
344 KB |
Output is correct |
11 |
Correct |
66 ms |
348 KB |
Output is correct |
12 |
Correct |
62 ms |
344 KB |
Output is correct |
13 |
Correct |
65 ms |
348 KB |
Output is correct |
14 |
Correct |
68 ms |
344 KB |
Output is correct |
15 |
Correct |
64 ms |
344 KB |
Output is correct |
16 |
Execution timed out |
2036 ms |
344 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2054 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2056 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
344 KB |
Output is correct |
2 |
Correct |
63 ms |
432 KB |
Output is correct |
3 |
Correct |
59 ms |
344 KB |
Output is correct |
4 |
Correct |
71 ms |
348 KB |
Output is correct |
5 |
Correct |
65 ms |
344 KB |
Output is correct |
6 |
Correct |
61 ms |
344 KB |
Output is correct |
7 |
Correct |
78 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
344 KB |
Output is correct |
9 |
Correct |
67 ms |
432 KB |
Output is correct |
10 |
Correct |
67 ms |
344 KB |
Output is correct |
11 |
Correct |
66 ms |
348 KB |
Output is correct |
12 |
Correct |
62 ms |
344 KB |
Output is correct |
13 |
Correct |
65 ms |
348 KB |
Output is correct |
14 |
Correct |
68 ms |
344 KB |
Output is correct |
15 |
Correct |
64 ms |
344 KB |
Output is correct |
16 |
Execution timed out |
2036 ms |
344 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2056 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
344 KB |
Output is correct |
2 |
Correct |
63 ms |
432 KB |
Output is correct |
3 |
Correct |
59 ms |
344 KB |
Output is correct |
4 |
Correct |
71 ms |
348 KB |
Output is correct |
5 |
Correct |
65 ms |
344 KB |
Output is correct |
6 |
Correct |
61 ms |
344 KB |
Output is correct |
7 |
Correct |
78 ms |
344 KB |
Output is correct |
8 |
Correct |
67 ms |
344 KB |
Output is correct |
9 |
Correct |
67 ms |
432 KB |
Output is correct |
10 |
Correct |
67 ms |
344 KB |
Output is correct |
11 |
Correct |
66 ms |
348 KB |
Output is correct |
12 |
Correct |
62 ms |
344 KB |
Output is correct |
13 |
Correct |
65 ms |
348 KB |
Output is correct |
14 |
Correct |
68 ms |
344 KB |
Output is correct |
15 |
Correct |
64 ms |
344 KB |
Output is correct |
16 |
Execution timed out |
2036 ms |
344 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |