Alex_tz307

USACO 2015 February Contest, Silver Problem 3. Superbull - APM cu Prim

Apr 21st, 2021
984
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("superbull.in");
  6. ofstream fout("superbull.out");
  7.  
  8. const int NMAX = 2e3 + 3;
  9. int a[NMAX], dp[NMAX];
  10. bitset<NMAX> viz;
  11.  
  12. void max_self(int &a, int b) {
  13.   a = max(a, b);
  14. }
  15.  
  16. void solve() {
  17.   int N;
  18.   fin >> N;
  19.   for (int i = 1; i <= N; ++i)
  20.     fin >> a[i];
  21.   long long ans = 0;
  22.   for (int i = 1; i <= N; ++i) {
  23.     int j = 0;
  24.     for (int k = 1; k <= N; ++k)
  25.       if (!viz[k] && dp[k] >= dp[j])
  26.         j = k;
  27.     ans += dp[j];
  28.     viz[j] = true;
  29.     for (int k = 1; k <= N; ++k)
  30.       max_self(dp[k], a[j] ^ a[k]);
  31.   }
  32.   fout << ans << '\n';
  33. }
  34.  
  35. void close_files() {
  36.   fin.close();
  37.   fout.close();
  38. }
  39.  
  40. int main() {
  41.   solve();
  42.   close_files();
  43.   return 0;
  44. }
  45.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×