Submission #1261841
Source Code Expand
// clang-format off #include <bits/stdc++.h> #define int long long int #define main signed main() #define bye return 0 #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++) #define all(v) (v).begin(), (v).end() #define prec(n) fixed << setprecision(n) #define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl #define clr(x, a) memset(x, a, sizeof(x)) #define sum(v) accumulate(all(v), 0) #define stlice(from, to) substr(from, (to) - (from) + 1) #define odd(n) ((n) % 2) #define even(n) (!odd(n)) #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define vi vector<int> #define vb vector<bool> #define vc vector<char> using namespace std; // clang-format on map<pair<int, int>, int> p; main { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; int s = sum(a); if (s % n == 0) { int avg = s / n; int c = 0; rep(i, n) c += (avg - a[i]) * (avg - a[i]); cout << c << endl; } else { int ava = s / n, avb = (s + n - 1) / n; int c = 0, d = 0; rep(i, n) { c += (ava - a[i]) * (ava - a[i]); d += (avb - a[i]) * (avb - a[i]); } cout << min(c, d) << endl; } bye; }
Submission Info
Submission Time | |
---|---|
Task | C - Be Together |
User | AyaMorisawa |
Language | C++14 (GCC 5.4.1) |
Score | 200 |
Code Size | 1402 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
0_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 1 ms | 256 KB |