/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 328.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 38ms 796.0 KiB
#5 Accepted 6ms 632.0 KiB
#6 Accepted 47ms 1.105 MiB
#7 Accepted 26ms 816.0 KiB
#8 Accepted 34ms 980.0 KiB
#9 Accepted 48ms 1.137 MiB
#10 Accepted 50ms 1.164 MiB
#11 Accepted 49ms 1.137 MiB
#12 Accepted 32ms 948.0 KiB
#13 Accepted 62ms 1.277 MiB
#14 Accepted 63ms 1.312 MiB
#15 Accepted 60ms 1.277 MiB
#16 Accepted 61ms 1.297 MiB
#17 Accepted 61ms 1.277 MiB
#18 Accepted 60ms 1.305 MiB
#19 Accepted 61ms 1.277 MiB
#20 Accepted 62ms 1.305 MiB
#21 Accepted 51ms 1.027 MiB
#22 Accepted 49ms 1.027 MiB
#23 Accepted 25ms 1.309 MiB
#24 Accepted 27ms 1.277 MiB
#25 Accepted 36ms 1.309 MiB
#26 Accepted 1ms 492.0 KiB
#27 Accepted 1ms 540.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;

ll dp[55][2] , n , k;
map < int , int > bit ;
ll Heart(int pos , bool afterBitMatchK) {

    if(pos < 0) return 0LL ;
    if(dp[pos][afterBitMatchK] != -1) return dp[pos][afterBitMatchK] ;
    if(k & (1LL << pos)) {
        dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , 1) + (bit[pos]) * (1LL << pos)) ;
        dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + (n - bit[pos]) * (1LL << pos)) ;
    }
    else {
        dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + (bit[pos]) * (1LL << pos)) ;
        if(afterBitMatchK) dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + ( n - bit[pos]) * (1LL << pos)) ;
    }

    return dp[pos][afterBitMatchK] ;
}
void solve()
{
   cin >> n >> k  ; ll a[n] ;
   for(int i = 0 ; i < n ; i++)
   {
      cin >> a[i] ;
      for(int j = 0 ; j < 50 ; j++)
      {
         if((1LL << j) & a[i]) bit[j]++ ;
      }
   }

   for(int i = 0 ; i <= 50 ; i++) dp[i][0] = dp[i][1] = -1 ;
   cout << Heart(50 , 0) << "\n" ;
}
int main()
{
     __Heart__
     //READ("input26.txt") ;
    // WRITE("output26.txt");
     int t ; t = 1 ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1054 Yet another challenge for Roy!
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-03 16:43:26
Judged At
2024-05-03 16:43:26
Judged By
Score
100
Total Time
63ms
Peak Memory
1.312 MiB