fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(int argc, char **argv) {
  5. int t;
  6. scanf("%d", &t);
  7. while (t-- != 0) {
  8. int n, freq[26] = { };
  9. char s[21];
  10. scanf("%d%s", &n, s);
  11. for (int i = 0; i < n; ++i)
  12. ++freq[s[i] - 'a'];
  13. int odd = 0;
  14. for (int i = 0; i < 26; ++i)
  15. if ((freq[i] & 1) == 1)
  16. ++odd;
  17. if (odd > 1) {
  18. puts("0");
  19. continue;
  20. }
  21. string z = "";
  22. for (int i = 0; i < 26; ++i)
  23. z += string(freq[i] >> 1, char(i + 'a'));
  24. int res = 0;
  25. do {
  26. ++res;
  27. } while (next_permutation(z.begin(), z.end()));
  28. printf("%d\n", res);
  29. }
  30. return 0;
  31. }
Runtime error #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty