fork download
  1. <?php
  2. error_reporting(E_ERROR);
  3. fscanf(STDIN,"%d\n",$T);
  4. while($T--)
  5. {
  6. $str = trim(fgets(STDIN));
  7. $str = explode(" ",$str);
  8. $N = intval($str[0]);
  9. $K = intval($str[1]);
  10. $rem = $N%$K;
  11. if($rem !== 0)
  12. {
  13. print("Not possible\n");
  14. continue;
  15. }
  16. $strarr = array();
  17. $div = $N/$K;
  18. while($N--)
  19. {
  20. $strarr[] = trim(fgets(STDIN));
  21. }
  22. $team = 0;
  23. $flag = 0;
  24. for($i=0;$i<count($strarr);)
  25. {
  26. $count = 1;
  27. $index = $i+1;
  28. $team +=1;
  29. for($j=$i+1;$j<count($strarr);$j++)
  30. {
  31. if($count===$K)
  32. break;
  33. if(strlen($strarr[$i]) === strlen($strarr[$j]))
  34. {
  35. $temp = $strarr[$j];
  36. $strarr[$j] = $strarr[$index];
  37. $strarr[$index] = $temp;
  38. $index +=1;
  39. $count++;
  40. }
  41. }
  42. $i = $index;
  43. }
  44. //print_r($count);
  45. if($div === $team && $flag !== 1)
  46. print("Possible\n");
  47. else
  48. print("Not possible\n");
  49. }
  50. ?>
Success #stdin #stdout 0.01s 24400KB
stdin
2
6 3
arjit
tijra
genius
chanda
ashish
arjit
4 2
bond
coder
bond
lol
stdout
    Possible
Not possible