QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792592 | #9806. Growing Tree | Carucao | WA | 2ms | 5668kb | C++20 | 4.3kb | 2024-11-29 11:45:50 | 2024-11-29 11:45:50 |
Judging History
answer
#include<bits/stdc++.h>
#define ls i<<1
#define rs i<<1|1
#define fi first
#define se second
#define min amin
#define max amax
#define eb emplace_back
using namespace std;
using ll=long long;
using LL=__int128;
using pii=pair<int,int>;
const int N=1<<20;
const int inf=0x3f3f3f3f;
const int p=998244353;
template<typename T=int>T read(){T x;cin>>x;return x;}
template<typename U,typename V>U min(const U &x,const V &y){return x<y?x:y;}
template<typename U,typename V>U max(const U &x,const V &y){return y<x?x:y;}
template<typename U,typename ...V>U min(const U &x,const V &...y){return min(x,min(y...));}
template<typename U,typename ...V>U max(const U &x,const V &...y){return max(x,max(y...));}
template<typename U,typename V>bool cmin(U &x,const V &y){return y<x?x=y,true:false;}
template<typename U,typename V>bool cmax(U &x,const V &y){return x<y?x=y,true:false;}
template<typename U,typename ...V>bool cmin(U &x,const V &...y){return cmin(x,min(y...));}
template<typename U,typename ...V>bool cmax(U &x,const V &...y){return cmax(x,max(y...));}
template<typename U,typename V>U qpow(U x,V n){U y(1);for(;n;n>>=1,x*=x)if(n&1)y*=x;return y;}
ll sqrt_floor(const ll &x){ll l=0,r=inf;while(l+1^r){ll mid=l+r>>1;(x<mid*mid?r:l)=mid;}return l;}
ll sqrt_ceil(const ll &x){ll l=-1,r=inf;while(l+1^r){ll mid=l+r>>1;(mid*mid<x?l:r)=mid;}return r;}
istream &operator>>(istream &is,LL &x){string a;is>>a;bool k=a[0]=='-';if(k)a=a.substr(1);x=0;for(char &t:a)x=x*10+t-48;if(k)x=-x;return is;}
ostream &operator<<(ostream &os,LL x){if(x<0)os<<'-',x=-x;string a;do a+=x%10|48;while(x/=10);reverse(a.begin(),a.end());return os<<a;}
mt19937 rng(time(0));
struct mint{
int x;
mint():x(){}
mint(const int &x):x(x<0?x+p:x){}
mint inv()const{return qpow(*this,p-2);}
mint operator-()const{return mint(x?p-x:x);}
mint &operator+=(const mint &t){return (x+=t.x)<p?0:x-=p,*this;}
mint &operator-=(const mint &t){return (x-=t.x)<0?x+=p:0,*this;}
mint &operator*=(const mint &t){return x=ll(x)*t.x%p,*this;}
mint &operator/=(const mint &t){return *this*=t.inv();}
mint operator+(const mint &t)const{return mint(*this)+=t;}
mint operator-(const mint &t)const{return mint(*this)-=t;}
mint operator*(const mint &t)const{return mint(*this)*=t;}
mint operator/(const mint &t)const{return mint(*this)/=t;}
operator int()const{return x;}
bool operator==(const mint &t)const{return x==t.x;}
friend mint operator+(const mint &x,const int &y){return mint(x)+=y;}
friend mint operator-(const mint &x,const int &y){return mint(x)-=y;}
friend mint operator*(const mint &x,const int &y){return mint(x)*=y;}
friend mint operator/(const mint &x,const int &y){return mint(x)/=y;}
friend mint operator+(const int &x,const mint &y){return mint(x)+=y;}
friend mint operator-(const int &x,const mint &y){return mint(x)-=y;}
friend mint operator*(const int &x,const mint &y){return mint(x)*=y;}
friend mint operator/(const int &x,const mint &y){return mint(x)/=y;}
friend istream &operator>>(istream &is,mint &t){return is>>t.x;}
friend ostream &operator<<(ostream &os,const mint &t){return os<<t.x;}
};
int a[N],n,ans;
vector<int>q[N];
void mg(vector<int>&a,vector<int>&b,vector<int>&c){
auto i=a.begin(),j=b.begin();
while(i!=a.end()||j!=b.end()){
if(*i==*j)return c.clear();
if(*i<*j){
c.eb(*i);
++i;
}
else{
c.eb(*j);
++j;
}
}
for(;i!=a.end();++i){
c.eb(*i);
}
for(;j!=b.end();++j){
c.eb(*j);
}
}
void dfs(int i,int s){
if(!--i)return void(ans=s);
mg(q[ls],q[rs],q[i]);
if(q[i].empty()){
++s;
if(s==ans||s+__lg(i)>n)return;
q[i]=q[ls];
dfs(i,s);
if(s<ans){
q[i]=q[rs];
dfs(i,s);
}
}
else{
dfs(i,s);
}
}
void solve(){
cin>>n;
int s=1<<n;
for(int i=2;i<s<<1;++i){
cin>>a[i];
a[i]+=a[i>>1];
if(i<s)q[i].clear();
else q[i].assign(1,a[i]);
}
ans=inf;
dfs(s,0);
cout<<(ans^inf?ans:-1)<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while(T--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5668kb
input:
3 2 1 2 4 3 2 1 2 1 2 3 3 2 1 2 1 2 3 3 1 1
output:
-1 -1 -1
result:
wrong answer 1st numbers differ - expected: '1', found: '-1'