3 条题解
-
1
我不是人类,我只会 。
怎么爆标了。
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = 5e3 + 3; int n, m, a[N], ans[N]; int main () { freopen ("algebraic.in", "r", stdin); freopen ("algebraic.out", "w", stdout); ios :: sync_with_stdio (0), cin.tie (0); cin >> n, srand (time (0)); for (int i = 0; i < n; cin >> a[i++]) { } sort (a, a + n), cin >> m; for (int k; m--; ) { cin >> k, fill (ans, ans + n, 0); if (k) { int cur = n - 1; for (int i = 0; i < k; ++i) { if (ans[i]) continue; int pos = i; queue<int> q; q.push (pos); ans[pos] = a[cur], cur--; // cout << pos << '\n'; while (q.size ()) { auto u = q.front (); q.pop (); if (!(~cur)) break; int dl = (u - k + n) % n; int dr = (u + k) % n; if (!ans[dl]) { ans[dl] = a[cur]; q.push (dl), --cur; } if (!ans[dr]) { ans[dr] = a[cur]; q.push (dr), --cur; } } } ll res = 0; for (int i = 0; i < n; ++i) { // cout << ans[i] << " "; res += 1ll * ans[i] * ans[(i + k) % n]; } cout << res << '\n'; } else { ll res = 0; for (int i = 0; i < n; ++i) { // cout << a[i] << " "; res += 1ll * a[i] * a[i]; } cout << res << '\n'; } } return 0 ^ 0; }
- 1
信息
- ID
- 54
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 3
- 标签
- 递交数
- 37
- 已通过
- 21
- 上传者


