fork download
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6. using pii = pair <int, int>;
  7. using pll = pair <ll, ll>;
  8.  
  9. #define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);
  10.  
  11. const int mx = 1e5 + 9;
  12.  
  13. ll a[mx];
  14. vector <int> perm_list[mx];
  15. vector <int> perm[mx];
  16.  
  17. int main() {
  18. FIO();
  19.  
  20. int tc; cin >> tc;
  21. while (tc--) {
  22. int n, m;
  23. cin >> n >> m;
  24.  
  25. for (int i = 1; i <= n; i++) {
  26. cin >> a[i];
  27. }
  28.  
  29. for (int i = 0; i < m; i++) perm_list[i].clear();
  30.  
  31. vector <int> p;
  32. for (int i = 2; i <= n; i++) p.push_back(i);
  33.  
  34. int sz = p.size();
  35. int cnt = 0;
  36. bool ok = false;
  37.  
  38. do {
  39. ll cost = 0;
  40. for (int i = 1; i < sz; i++) {
  41. cost += (a[p[i]] ^ a[p[i - 1]]);
  42. cost %= m;
  43. }
  44.  
  45. cost += (a[p.back()] ^ a[1]);
  46. cost += (a[p[0]] ^ a[1]);
  47. cost %= m;
  48.  
  49. perm[cnt].clear();
  50.  
  51. perm[cnt].push_back(1);
  52. for (int x : p) perm[cnt].push_back(x);
  53. perm[cnt].push_back(1);
  54.  
  55. perm_list[cost].push_back(cnt);
  56.  
  57. cnt++;
  58.  
  59. if (perm_list[cost].size() == 3) {
  60. cout << "Yes\n";
  61. for (int idx : perm_list[cost]) {
  62. for (int x : perm[idx]) {
  63. cout << x << " ";
  64. }
  65. cout << '\n';
  66. }
  67.  
  68. ok = true;
  69. break;
  70. }
  71.  
  72. } while (next_permutation(p.begin(), p.end()));
  73.  
  74. if (!ok) cout << "No\n";
  75. }
  76. }
  77.  
Success #stdin #stdout 0.01s 9008KB
stdin
2
4 20
0 1 1 0
4 30
5 3 1 7
stdout
Yes
1 2 3 4 1 
1 3 2 4 1 
1 4 2 3 1 
No