Advertisement
a53

palind

a53
Aug 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define INF 2000000000
  3. #define MAXN 7001
  4. #define ABS(x) ((x) < 0 ? (-(x)) : (x))
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin ("palind.in");
  9. ofstream fout ("palind.out");
  10.  
  11. int N, x, A[2][MAXN], cnt[MAXN];
  12. int sol[2][2];
  13.  
  14. void Go (int t) {
  15. int i, nr, val, mmin = INF;
  16. memset (cnt, 0, sizeof(cnt));
  17. for (val = nr = 0, i = 1; i < MAXN; i ++)
  18. val += nr, val += A[t][i - 1], nr += A[t][i - 1], cnt[i] += val;
  19. for (nr = val = 0, i = MAXN - 2; i >= 1; i --)
  20. val += nr, val += A[t][i + 1], nr += A[t][i + 1], cnt[i] += val;
  21. for (nr = 0, i = 1; i < MAXN; i ++) {
  22. if (cnt[i] == mmin)
  23. nr ++;
  24. if (cnt[i] < mmin)
  25. mmin = cnt[i], nr = 1;
  26. }
  27. sol[t][0] = mmin, sol[t][1] = nr;
  28. }
  29.  
  30. void Solve () {
  31. memset (A, 0, sizeof(A));
  32. fin >> N;
  33. for(int i = 1; i <= N; i ++)
  34. fin >> x, A[i & 1][x] ++;
  35. Go (0), Go (1);
  36. fout << sol[0][0] + sol[1][0] << ' ' << sol[0][1] * sol[1][1] << '\n';
  37. }
  38.  
  39. int main () {
  40. int T;
  41. fin >> T;
  42. while (T --)
  43. Solve();
  44. fin.close();
  45. fout.close();
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement