Submission #1604257


Source Code Expand

#include <bits/stdc++.h>
#define INF (1<<21)
using namespace std;

int main(){

  int n, tmp = 0;
  int v[210] = {}
  long long ans = INF;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < 101; i++){
    long long sum = 0;
    for(int j = 0; j < n; j++){
      sum += (i - v[j]) * (i - v[j]);
    }
    ans = min(ans, sum);
  }
  if(tmp/n == abs(v[0]) && tmp%n == 0) ans = 0;
  if(ans == INF) ans = 0;
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task C - Be Together
User swkfn
Language C++14 (GCC 5.4.1)
Score 0
Code Size 487 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:9:3: error: expected ‘,’ or ‘;’ before ‘long’
   long long ans = INF;
   ^
./Main.cpp:17:5: error: ‘ans’ was not declared in this scope
     ans = min(ans, sum);
     ^
./Main.cpp:19:40: error: ‘ans’ was not declared in this scope
   if(tmp/n == abs(v[0]) && tmp%n == 0) ans = 0;
                                        ^
./Main.cpp:20:6: error: ‘ans’ was not declared in this scope
   if(ans == INF) ans = 0;
      ^
./Main.cpp:21:11: error: ‘ans’ was not declared in this scope
   cout << ans << endl;
           ^