50pts,TLE求助
  • 板块P8438 极寒之地
  • 楼主baiABCiBaraki545
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/7/18 09:29
  • 上次更新2023/10/27 19:46:57
查看原帖
50pts,TLE求助
404961
baiABCiBaraki545楼主2022/7/18 09:29

RT,不知道哪里常数大了过不去

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull a[32], ans;
ull yh[32];
int f(ull x)
{
   int cnt = 0;
   while(x>>=1)++cnt;
   return cnt;
}
int main()
{
   ios::sync_with_stdio(0);
   int n; cin >> n;
   for(int i = 0; i < n; ++i)
      cin >> a[i];
   for(ull S = 1; S < 1ull<<n; ++S)
   {
      ull lb = S&-S;
      int cnt = f(lb);
      if(!(S&(S-1)))
      {
         yh[cnt] = a[cnt];
         ans ^= S*yh[cnt];
      }
      else
      {
         lb ^= S;
         ull lb2 = lb&-lb;
         int c2 = f(lb2);
         yh[cnt] = yh[c2]^a[cnt];
         ans ^= S*yh[cnt];
      }
   }
   cout << ans << '\n';
   return 0;
}
2022/7/18 09:29
加载中...