Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "spoj.h"
- #include <iostream>
- #include <string>
- using namespace std;
- char temp1[200];
- string Si[10001];
- int n, len, P[10001], x, F[10001], S[1000001], sum1;
- int main()
- {
- spoj_init();
- fscanf(spoj_p_in, "%d", &n);
- spoj_assert(n=10000);
- for (int i = 1; i <= n; ++i) {
- fscanf(spoj_p_in, "%s", temp1);
- Si[i] = temp1;
- len += Si[i].length();
- }
- spoj_assert(len==1000000);
- for(int i=1;i<= len;i++)
- {
- fscanf(spoj_t_out, "%d", &x);
- spoj_assert( (1<=x) && (x <=n) );
- F[x]++;
- spoj_assert(F[x]<=Si[x].length());
- S[i] = (Si[x][F[x]-1] - '0');
- }
- for(int i=1;i<=n;i++)
- {
- spoj_assert(F[i] == Si[i].length());
- }
- for(int i=2;i<=len;i++)
- {
- sum1 += ( (S[i] - S[i-1]) * (S[i] - S[i-1]) );
- }
- fprintf(spoj_score,"%d\n", sum1);
- return SPOJ_RV_POSITIVE;
- }
Add Comment
Please, Sign In to add comment