fork download
  1. // ~~ icebear love atttt ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int MOD = 1e9 + 7;
  6. const int inf = 1e9 + 27092008;
  7. const long long INF = 1e18 + 27092008;
  8. const int N = 1020 + 5;
  9. int n, v[N];
  10. char cur[N], res[N];
  11. int ans;
  12. bitset<N> vis[1 << 2][201][N];
  13. struct State {
  14. int i, j, k, mask;
  15. };
  16. queue<State> states;
  17.  
  18. void dfs(int mask, int i, int x, int y, int z) {
  19. if (i == n) {
  20. if (mask == (1 << 2) - 1 && ans < x + y + z) {
  21. ans = x + y + z;
  22. for(int i = 0; i < n; i++) res[i] = cur[i];
  23. }
  24. return;
  25. }
  26. if (vis[mask][i][x][y]) return;
  27. vis[mask][i][x][y] = true;
  28. states.push({i, x, y, mask});
  29. cur[i] = 'P';
  30. dfs(mask | (1 << 0), i + 1, x ^ v[i], y, z);
  31. cur[i] = 'V';
  32. dfs(mask | (1 << 1), i + 1, x, y ^ v[i], z);
  33. cur[i] = 'H';
  34. dfs(mask, i + 1, x, y, z ^ v[i]);
  35. }
  36.  
  37. int main() {
  38. #define task "chemistry"
  39. if (fopen(task".inp", "r")) {
  40. freopen(task".inp", "r", stdin);
  41. freopen(task".out", "w", stdout);
  42. }
  43. ios_base::sync_with_stdio(0);
  44. cin.tie(0); cout.tie(0);
  45. int subtask; cin >> subtask;
  46. while(cin >> n) {
  47. if (!n) break;
  48. for(int i = 0; i < n; i++) cin >> v[i];
  49. ans = -1;
  50. dfs(0, 0, 0, 0, 0);
  51. for(int i = 0; i < n; i++) cout << res[i];
  52. cout << '\n';
  53. while(!states.empty()) {
  54. auto X = states.front(); states.pop();
  55. vis[X.mask][X.i][X.j][X.k] = false;
  56. }
  57. }
  58. return 0;
  59. }
  60.  
  61.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty