Submission #835772


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
gl(n);
int a[1005];
rep(i,1,n)cin>>a[i];
ll ans=1e18;

rep(kk,-300,300)
{
	ll s=0;
	rep(i,1,n)
	{
		s+=(kk-a[i])*(kk-a[i]);
	}
	ans=min(ans,s);
}
ol(ans);
return 0;
}

Submission Info

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

Test Cases

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