Submission #835826


Source Code Expand

Copy
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;

ll a[110];
inline ll norm(ll n){return n*n;}

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];

	ll ans=0LL;
	rep(i,n) ans+=norm(a[i]-a[0]);
	rep(i,-100,101){
		ll cur=0LL;
		rep(j,n) cur+=norm(a[j]-i);
		chmin(ans,cur);
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Be Together
User Hec
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1168 Byte
Status AC
Exec Time 4 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 4
AC × 15
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 4 ms 256 KB
0_001.txt AC 4 ms 256 KB
0_002.txt AC 4 ms 256 KB
0_003.txt AC 4 ms 256 KB
1_004.txt AC 4 ms 256 KB
1_005.txt AC 4 ms 256 KB
1_006.txt AC 4 ms 256 KB
1_007.txt AC 4 ms 256 KB
1_008.txt AC 4 ms 256 KB
1_009.txt AC 4 ms 256 KB
1_010.txt AC 4 ms 256 KB
1_011.txt AC 4 ms 256 KB
1_012.txt AC 4 ms 256 KB
1_013.txt AC 4 ms 256 KB
1_014.txt AC 4 ms 256 KB