搜索
热搜: NOIP OIer 神牛
查看: 364|回复: 1

帮帮我2866

[复制链接]

主题

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2023-4-8 09:23:26 | 显示全部楼层 |阅读模式
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. #pragma GCC optimize(2)
  5. inline int read(){
  6.         int x=0,f=0;char ch=getchar();
  7.         while(!isdigit(ch)){
  8.                 f|=ch=='-';
  9.                 ch=getchar();
  10.         }
  11.         while(isdigit(ch)){
  12.                 x=x*10+(ch^48);
  13.                 ch=getchar();
  14.         }
  15.         return f?-x:x;
  16. }
  17. inline void write(int x){
  18.         if(x<0)
  19.                 putchar('-'),x=-x;
  20.         if(x>9)
  21.                 write(x/10);
  22.         putchar(x%10+'0');
  23.         return;
  24. }
  25. int n,tot=0,f[2005],a[2005];
  26. struct node{
  27.         int u,v,w;
  28.         bool operator< (const node& a) const{
  29.                 return w>a.w;
  30.         }
  31. }e[5000005];
  32. inline void add(int u,int v,int w){
  33.         e[++tot].v=v;
  34.         e[tot].u=u;
  35.         e[tot].w=w;
  36. }
  37. inline int find(int x){
  38.         if(f[x]==x)
  39.                 return x;
  40.         else return f[x]=find(f[x]);
  41. }
  42. inline int kruskal(){
  43.         int ans=0,cnt=0;
  44.         for(int i=1;i<=tot;++i){
  45.                 int f1=find(e[i].u),f2=find(e[i].v);
  46.                 if(f1!=f2){
  47.                         f[f1]=f2;
  48.                         ans+=e[i].w;
  49.                         if(++cnt==n-1)
  50.                                 break;
  51.                 }
  52.         }
  53.         return ans;
  54. }
  55. signed main(){
  56.         n=read();
  57.         for(int i=1;i<=n;++i)
  58.                 f[i]=i,a[i]=read();
  59.         for(int i=1;i<=n;++i)
  60.                 for(int j=1;j<=n;++j)
  61.                         if(i!=j)
  62.                                 add(i,j,a[i]^a[j]);
  63.         sort(e+1,e+tot+1);
  64.         write(kruskal());
  65.         return 0;
  66. }
复制代码
怎么卡常啊,一直TLE,o2开了,inline用了,快读快写板子也用了,register不让用
怎么卡常啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
题目传送门
回复

使用道具 举报

主题

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2023-4-8 09:23:57 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

津ICP备19006949号-1 | 津公网安备12010102000465号

快速回复 返回顶部 返回列表