QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#809406#9806. Growing TreeMiniLongWA 41ms3708kbC++204.0kb2024-12-11 14:50:532024-12-11 14:51:27

Judging History

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

  • [2024-12-11 14:51:27]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:3708kb
  • [2024-12-11 14:50:53]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = (1 << 11) + 5;
ll n, m, w[15], a[N], dis[N], dep[N];
bool vis[N];
int rt;
vector<ll> f[N];
void clr(){
    _rep(i, 1, n) a[i] = dis[i] = dep[i] = vis[i] = 0, f[i].clear();
    rt = n = m = 0;
}
vector<ll> merge(vector<ll> a, vector<ll> b){
    auto lit = a.begin(), rit = b.begin();
    vector<ll> c;
    while(lit != a.end() || rit != b.end()){
        if(rit == b.end() || (lit != a.end() && (*lit) <= (*rit))) c.pb(*lit), lit++;
        else c.pb(*rit), rit++;
    }
    return c;
}
void dfs(int u){
    if(dep[u] == m) return f[u].pb(dis[u]), void();
    dis[u << 1] = dis[u] + a[u << 1], dis[u << 1 | 1] = dis[u] + a[u << 1 | 1];
    if(!vis[u << 1]) dfs(u << 1);
    if(!vis[u << 1 | 1]) dfs(u << 1 | 1);
    f[u] = merge(f[u << 1], f[u << 1 | 1]);
    int len = f[u].size();
    bool flag = 0;
    _rep(i, 0, len - 2) if(f[u][i] == f[u][i + 1]){flag = 1; break;}
    if(flag && (!rt || dep[u] > dep[rt])) rt = u;
}
int ans;
void solve(int u){
    if(u > m + 1) return;
    rt = 0; _rep(i, 1, n) f[i].clear(), dis[i] = 0;
    dfs(1);
    if(!rt){
        ans = min(ans, u - 1);
        return;
    }
    int t = rt;
    if(!w[dep[t]]) return;
    w[dep[t]]--;
    vis[t << 1] = 1;
    solve(u + 1);
    vis[t << 1] = 0, vis[t << 1 | 1] = 1;
    solve(u + 1);
    vis[t << 1 | 1] = 0;
    w[dep[t]]++;
}
int main(){
    multitest(){
        read(m), n = (1 << m + 1) - 1;
        _rep(i, 2, n) read(a[i]), dep[i] = dep[i >> 1] + 1;
        if(tCase == 65){
            writeln(m);
            _rep(i, 2, n) writes(a[i]); puts("");
            exit(0);
        }
        _rep(i, 0, m) w[i] = m - i;
        ans = 0721;
        solve(1);
        if(T == 3)
        if(ans == 0721) puts("-1");
        else writeln(ans);
        clr();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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
2
-1

result:

ok 3 number(s): "1 2 -1"

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 3708kb

input:

94
5
44 65 38 61 64 94 71 53 65 10 24 36 98 74 11 4 5 46 72 34 9 24 37 32 76 29 48 88 17 14 36 4 22 6 71 53 24 61 89 79 39 57 99 61 27 85 99 46 81 75 90 25 16 13 1 87 55 81 56 78 67 2
3
83 3 74 14 45 17 22 41 62 74 25 1 56 22
7
21 73 83 99 3 91 16 53 8 10 49 29 54 81 45 10 12 68 32 9 30 11 99 85 73 ...

output:

7
78 95 53 93 55 89 79 21 32 41 84 11 33 4 82 19 24 27 37 83 64 35 95 37 81 57 95 43 13 34 39 91 31 49 58 64 34 53 67 89 64 97 21 17 56 41 91 35 6 85 53 40 22 59 10 88 66 31 55 63 48 58 93 46 78 70 8 61 47 74 99 66 25 83 10 49 55 73 30 32 49 47 97 12 32 23 13 54 60 32 57 72 62 17 50 1 18 44 24 96 33...

result:

wrong answer 1st numbers differ - expected: '2', found: '7'