arjunarul

Custom Judge - Challenge problem

Mar 8th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include "spoj.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. char temp1[200];
  8. string Si[10001];
  9. int n, len, P[10001], x, F[10001], S[1000001], sum1;
  10.  
  11. int main()
  12. {
  13.  
  14.     spoj_init();
  15.  
  16.     fscanf(spoj_p_in, "%d", &n);
  17.     spoj_assert(n=10000);
  18.  
  19.     for (int i = 1; i <= n; ++i) {
  20.         fscanf(spoj_p_in, "%s", temp1);
  21.         Si[i] = temp1;
  22.         len += Si[i].length();
  23.     }
  24.    
  25.     spoj_assert(len==1000000);
  26.    
  27.     for(int i=1;i<= len;i++)
  28.     {
  29.         fscanf(spoj_t_out, "%d", &x);
  30.         spoj_assert( (1<=x) && (x <=n) );
  31.         F[x]++;
  32.         spoj_assert(F[x]<=Si[x].length());
  33.         S[i] = (Si[x][F[x]-1] - '0');
  34.     }
  35.    
  36.     for(int i=1;i<=n;i++)
  37.     {
  38.         spoj_assert(F[i] == Si[i].length());
  39.     }
  40.    
  41.     for(int i=2;i<=len;i++)
  42.     {
  43.         sum1 += ( (S[i] - S[i-1]) * (S[i] - S[i-1]) );
  44.     }
  45.    
  46.    
  47.     fprintf(spoj_score,"%d\n", sum1);
  48.  
  49.     return SPOJ_RV_POSITIVE;
  50. }
Add Comment
Please, Sign In to add comment