Advertisement
mrlolthe1st

Untitled

Sep 18th, 2023
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <assert.h>
  3.  
  4. #include <algorithm>
  5. #include <array>
  6. #include <chrono>
  7. #include <fstream>
  8. #include <functional>
  9. #include <iomanip>
  10. #include <iostream>
  11. #include <map>
  12. #include <numeric>
  13. #include <optional>
  14. #include <queue>
  15. #include <random>
  16. #include <set>
  17. #include <sstream>
  18. #include <string>
  19. #include <thread>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22. #include <variant>
  23. #include <vector>
  24.  
  25. using namespace std;
  26.  
  27. const long long MOD = 1400305337;
  28. const long long MOD2 = 1e9 + 9;
  29. vector<int> a;
  30. int n;
  31. int mex[5001][5001];
  32. unordered_set<int> v[5005];
  33. int ans = 0;
  34. void solve(int i, int prev) {
  35.   ans = max(ans, prev);
  36.   if (i == n) return;
  37.   if (v[i].count(prev)) return;
  38.   v[i].insert(prev);
  39.   for (int j = 0; j + i < n; ++j) {
  40.     solve(i + j + 1, prev);
  41.     solve(i + j + 1, prev ^ mex[i][i + j]);
  42.   }
  43. }
  44.  
  45. signed main(int64_t argc, char** argv) {
  46.   ios::sync_with_stdio(0);
  47.   cin.tie(0);
  48.   cout.tie(0);
  49.   int t;
  50.   cin >> t;
  51.   while (t--) {
  52.     cin >> n;
  53.     a.resize(n);
  54.     for (auto& e : a) cin >> e;
  55.     for (int i = 0; i < n; ++i) v[i].clear();
  56.     for (int i = 0; i < n; ++i) {
  57.       set<int> x;
  58.       for (int j = 0; j <= n + 1; ++j) x.insert(j);
  59.       for (int j = i; j < n; ++j) {
  60.         x.erase(a[j]);
  61.         mex[i][j] = *x.begin();
  62.       }
  63.     }
  64.     ans = 0;
  65.     solve(0, 0);
  66.     cout << ans << "\n";
  67.   }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement