QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#811388#9806. Growing TreeSuhyCompile Error//Python33.9kb2024-12-12 19:00:252024-12-12 19:00:29

Judging History

你现在查看的是最新测评结果

  • [2024-12-12 19:00:29]
  • 评测
  • [2024-12-12 19:00:25]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nd second
#define st first
#define lb(x) ((x) & (-(x)))
#define b(x) ((x) / sqn + 1)
#define ppc(x) (__builtin_popcountll(x))
#define brekp cout<<"OK"<<endl
#define GetMid int mid = (l + r) >> 1
#define ls in * 2
#define rs in * 2 + 1
#define updt(x, y) (x = max(x, y))
#define getb(x, y) (((x) >> (y)) & 1)
#define llen (mid - l + 1)
#define rlen (r - mid)
#define ld long double
#define uc unsigned char
#define pii pair <int, int>
#define pll pair <ll, ll>
#define set multiset
//#define int long long
#pragma GCC optimize(3)
 
using namespace std;

const int maxn = 1100;
const int maxm = 2200;
const int z = 'z' - 'a';
const int p = 998244353;
const int inf = 1000000;
const ull bas = 37;
const ull cas = 91;
const int lw = 200000;
const ld pi = 3.14159265358979323846264338327950288419716937937510;
int bs[2] = {37, 46};

ll read()
{
   ll x = 0, fl = 0;
   char c = 0;
   while(c < '0' || '9' < c)
      c = getchar(), fl |= (c == '-');
   while('0' <= c && c <= '9')
      x = x * 10 + c - '0', c = getchar();
   return (fl ? -x : x);
}
int WriteSta[35], WriteTop;
void write(int x, char c)
{
    do WriteSta[WriteTop ++] = x % 10, x /= 10;
    while(x);
    while(WriteTop) putchar(WriteSta[-- WriteTop] + '0');
    putchar(c);
}
int pls(int x, int y)
   {return (x + y >= p) ? (x + y - p) : (x + y);}
int mns(int x, int y)
   {return (x >= y) ? (x - y) : (x + p - y);}
int powm(int x, int y)
{
   if(y == 0) return 1;
   int ne = powm(x, y / 2);
   ne = 1ll * ne * ne % p;
   if(y % 2) return 1ll * ne * x % p;
   else return ne % p;
}
int gcd(int x, int y)
{
   if(x < y) swap(x, y);
   if(y == 0) return x;
   return gcd(y, x % y);
}

int t;
int n, a[maxm], val[maxm], lg2[maxn], cnt, mdf[maxn], islca[maxn][2];
map <int, int> rnk;
bitset <maxn> bts[maxn][2];


signed main()
{
   cin>>t;
   while(t --)
   {
      cin>>n;
      int tp = (1 << n + 1);
      for(int i = 2; i < tp; i ++)
         a[i] = read(), lg2[i] = log2(i);

      for(int i = (1 << n); i < tp; i ++)
      {
         for(int in = i; in; in >>= 1)
            val[i] += a[in];
         if(!rnk[val[i]]) rnk[val[i]] = ++ cnt;
         //cout<<i<<' '<<rnk[val[i]]<<endl;
      }
      
      for(int in = tp - 1; in >= 1; in --)
      {
         if(lg2[in] == n) bts[in][0][rnk[val[in]]] = 1;
         else 
         {
            bts[in][0] = bts[ls][0] | bts[rs][0];
            islca[in][0] = (bts[ls][0] & bts[rs][0]).count();
         }
      }

      int ans = n + 1;
      for(int i = 0; i < (1 << n); i ++)
      {
         int cnt = 0, lst = 1;
         memset(mdf, 0, sizeof mdf);
         for(int j = (1 << n) - 1; j >= 1; j --)
         {
            if(islca[j][mdf[j]])
            {
               // cout<<i<<' '<<j<<endl;
               lst --; cnt ++;
               //cout<<i<<' '<<j<<' '<<lst<<endl;
               if(lst < 0 || cnt > n)
               {
                  cnt *= -1;
                  break;
               }
               mdf[j] = 1;
               int son = j * 2 + ((i >> n - cnt) & 1);
               bts[j][1] = bts[son][mdf[son]];
               for(int in = (j >> 1); in; in >>= 1)
               {
                  mdf[in] = 1;
                  bts[in][1] = bts[ls][mdf[ls]] | bts[rs][mdf[rs]];
                  islca[in][1] = (bts[ls][0] & bts[rs][0]).count();
               }
            }
            if(ppc(j) == 1) lst ++;
         }
         //cout<<cnt<<endl;
         if(cnt >= 0) ans = min(ans, cnt);
         if(abs(cnt) < n) i |= ((1 << (n - abs(cnt))) - 1);
      }

      printf("%d\n", ((ans > n) ? -1 : ans));
      rnk.clear();
      memset(islca, 0, sizeof islca);
      cnt = 0;
      memset(val, 0, sizeof val);
      for(int i = 1; i < tp; i ++)
         bts[i][0].reset();
   }
}

详细

  File "answer.code", line 64
    ne = 1ll * ne * ne % p;
         ^
SyntaxError: invalid decimal literal