Skip to content

Instantly share code, notes, and snippets.

@msg555
Created February 10, 2013 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg555/4747671 to your computer and use it in GitHub Desktop.
Save msg555/4747671 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Round 2
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;
long long VT[500];
long long ED[500];
int main() {
VT[0] = 2;
VT[1] = 3;
ED[0] = 1;
ED[1] = 2;
for(int i = 2; i < 500; i++) {
VT[i] = VT[i - 1] + i;
ED[i] = ED[i - 1] + i + 1;
}
int T; scanf("%d", &T);
for(int t = 1; t <= T; t++) {
printf("Case #%d: ", t);
int N; scanf("%d", &N);
long long E = 0;
long long V = 0;
long long S = 0;
for(int i = 0; i < N; i++) {
int A; scanf("%d", &A);
V += S * (A + 1) + VT[A];
E += 2 * S * (A + 1) + ED[A];
S += A + 1;
}
printf("%lld\n", E - V + 1 + 2 * N);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment