/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 42ms 1.008 MiB
#5 Accepted 7ms 532.0 KiB
#6 Accepted 52ms 1.105 MiB
#7 Accepted 29ms 880.0 KiB
#8 Accepted 38ms 976.0 KiB
#9 Accepted 52ms 1.141 MiB
#10 Accepted 54ms 1.168 MiB
#11 Accepted 54ms 1.137 MiB
#12 Accepted 36ms 944.0 KiB
#13 Accepted 68ms 1.305 MiB
#14 Accepted 68ms 1.305 MiB
#15 Accepted 65ms 1.305 MiB
#16 Accepted 66ms 1.312 MiB
#17 Accepted 67ms 1.312 MiB
#18 Accepted 65ms 1.312 MiB
#19 Accepted 69ms 1.309 MiB
#20 Accepted 69ms 1.066 MiB
#21 Accepted 57ms 1.164 MiB
#22 Accepted 54ms 1.133 MiB
#23 Accepted 27ms 1.305 MiB
#24 Accepted 30ms 1.316 MiB
#25 Accepted 40ms 1.305 MiB
#26 Accepted 1ms 532.0 KiB
#27 Accepted 1ms 320.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-08-09 23:06:29
Judged At
2024-11-11 03:20:31
Judged By
Score
100
Total Time
69ms
Peak Memory
1.316 MiB