/ SeriousOJ /

Record Detail

System Error


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 332.0 KiB
#2 Wrong Answer 1ms 540.0 KiB
#3 Wrong Answer 1ms 540.0 KiB
#4 System Error 7ms 8.547 MiB
#5 System Error 8ms 8.453 MiB
#6 System Error 7ms 8.527 MiB
#7 System Error 7ms 8.527 MiB
#8 System Error 7ms 8.527 MiB
#9 System Error 7ms 8.41 MiB
#10 System Error 44ms 8.547 MiB
#11 System Error 8ms 8.402 MiB
#12 System Error 7ms 8.621 MiB
#13 System Error 7ms 8.512 MiB
#14 System Error 7ms 8.465 MiB
#15 System Error 7ms 8.527 MiB
#16 System Error 7ms 8.527 MiB
#17 System Error 7ms 8.527 MiB
#18 System Error 7ms 8.527 MiB
#19 System Error 7ms 8.527 MiB
#20 System Error 7ms 8.527 MiB
#21 System Error 7ms 8.492 MiB
#22 System Error 7ms 8.527 MiB
#23 System Error 7ms 8.477 MiB
#24 System Error 7ms 8.523 MiB
#25 System Error 7ms 8.496 MiB
#26 Wrong Answer 1ms 540.0 KiB
#27 Wrong Answer 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;
void solve()
{
   ll n , k ; cin >> n >> k ; ll a[n] ;
    map < int , int > bit ;
   for(int i = 0 ; i < n ; i++)
   {
      cin >> a[i] ;
      for(int j = 0 ; j < 50 ; j++)
      {
         if((1LL << j) & a[i]) bit[j]++ ;
      }
   }
   ll x = 0 , Ans = 0 , Ans2 = 0;
   for(ll i = 50 ; i >= 0 ; i--)
   {
       ll zero = n - bit[i] ;
       ll add = x + (1LL << i) ;
      // cout << zero << " " << bit[i] << " " << k << " " << add << endl ;
       if(zero >= bit[i] && add <= k) x = add ;

   }
  // cout << x << endl ;
   for(int i = 0 ; i < n ; i++) Ans += (a[i] ^ x) ;
   x = 0 ;
    for(ll i = 0 ; i <= 50 ; i++)
   {
       ll zero = n - bit[i] ;
       ll add = x + (1LL << i) ;
      // cout << zero << " " << bit[i] << " " << k << " " << add << endl ;
       if(zero >= bit[i] && add <= k) x = add ;

   }
   for(int i = 0 ; i < n ; i++) Ans2 += (a[i] ^ x) ;

   cout << max(Ans , Ans2) << "\n" ;

}
int main()
{
     __Heart__
     //READ("0out.txt") ;
     int t ; cin >> t ; 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:33:25
Judged At
2024-05-03 16:33:25
Judged By
Score
0
Total Time
44ms
Peak Memory
8.621 MiB