C求优化

学术版

Special_Tony @ 2024-07-24 00:46:01

rt,其它应该没啥问题,但是1ll<<use会爆炸,求优化QAQ

# pragma GCC optimize("Ofast,no-stack-protector")

# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

# include <bits/stdc++.h>

# define I return

# define AK 0

# define IOI ;

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

int t, n, sum, x, lst, use;

bool flag;

int main () {

    ios::sync_with_stdio (0);

    cin.tie (0);

    cout.tie (0);

    cin >> t;

    while (t --) {

        cin >> n >> lst, sum = use = 0, flag = 0;

        for (int i = 1; i < n; ++ i) {

            cin >> x;

            if (lst != 1 && x == 1)
                flag = 1;

            if (flag)
                continue ;

            use = ceil (log2 (max (1.0, ceil (log2 (lst) / log2 (x) * (1ll << use)))));
//          cerr << use << ' ';
            sum += use;

            lst = x;

        }

        cout << (flag ? -1 : sum) << '\n';

    }

    I AK IOI

}
/*
1
9
16 2 4 2 256 2 4 2 8
*/

by AfterFullStop @ 2024-07-24 08:48:55

@Special_Tony 我最后设了个 1e-9,但估计其他也行。


by Special_Tony @ 2024-07-24 08:53:33

@AfterFullStop 为啥我本地没问题cf就挂了捏


by AfterFullStop @ 2024-07-24 08:57:00

@Special_Tony 前面是 1 要判掉


by Special_Tony @ 2024-07-24 08:58:10

@AfterFullStop thx


by Special_Tony @ 2024-07-24 08:59:35

@AfterFullStop AC了,thx!


上一页 |