QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205859#7560. Computer Networkucup-team1516#WA 2ms10024kbC++203.6kb2023-10-07 17:39:092023-10-07 17:39:09

Judging History

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

  • [2023-10-07 17:39:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10024kb
  • [2023-10-07 17:39:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < ll(n); i++)
#define repll3(i, a, b) for (ll i = a; i < ll(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < ll(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = n - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= ll(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= ll(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int n;
ll a[1000010], b[1000010], c[1000010], d[1000010];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n;
    rep (i, n) cin >> a[i];
    rep (i, n) c[i] = a[(i + 1) % n] - a[i];
    rep (i, n) cin >> b[i];
    rep (i, n) d[i] = b[(i + 1) % n] - b[i];

    ll ans = linf;
    rep (i, 31) {
        ll mn = 0, mx = 0, sum = 0;
        bool judge = true;
        vector<ll> e(n);
        rep (j, n) {
            e[j] += c[j] - d[j] * (1ll << i);
            judge &= abs(e[j]) <= (1ll << i) - 1;
        }

        rep (j, n) {
            sum += e[j];
            chmin(mn, sum), chmax(mx, sum);
        }

        judge &= (mx - mn) <= (1ll << i) - 1;
        ll x = max(0ll, a[0] - b[0] * (1ll << i));
        chmax(x, -mn);
        if (x <= (1ll << i) - 1 - mx && judge) {
            ll dis = b[0] * (1ll << i) + x - a[0];
            ll res = i;
            vector<ll> cnt(i + 2);
            rrep (j, i + 1) {
                cnt[j] = dis / (1ll << j);
                dis %= 1ll << j;
            }

            rep (j, i + 1) {
                if (cnt[j] == 2) cnt[j + 1] += 1, cnt[j] = 0;
                if (cnt[j] && x + (1 << j) <= (1ll << i) - 1 - mx) {
                    x += 1 << j;
                    cnt[j + 1]++, cnt[j] = 0;
                }
            }
            chmin(ans, 1ll * i + accumulate(all(cnt), 0ll));
        }
    }

    cout << (ans == linf ? -1 : ans) << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9948kb

input:

5
1 2 3 4 5
6 6 6 6 7

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 1ms
memory: 9716kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9784kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: 0
Accepted
time: 0ms
memory: 9796kb

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9784kb

input:

1
249912
43

output:

26

result:

ok 1 number(s): "26"

Test #6:

score: 0
Accepted
time: 1ms
memory: 9728kb

input:

2
52522336 155670
52532336 165670

output:

10000

result:

ok 1 number(s): "10000"

Test #7:

score: 0
Accepted
time: 1ms
memory: 10024kb

input:

2
141839218 538313890
17731054 67290388

output:

1155

result:

ok 1 number(s): "1155"

Test #8:

score: 0
Accepted
time: 0ms
memory: 9788kb

input:

2
678834913 571995689
84855772 71500869

output:

1411

result:

ok 1 number(s): "1411"

Test #9:

score: 0
Accepted
time: 1ms
memory: 9780kb

input:

10
66 0 65 10 40 1 44 29 13 15
84 18 83 28 58 19 62 47 31 33

output:

18

result:

ok 1 number(s): "18"

Test #10:

score: -100
Wrong Answer
time: 1ms
memory: 9720kb

input:

10
0 74752 70656 67584 29696 44032 80896 22528 1024 52224
2 75 71 68 31 45 81 24 3 53

output:

11

result:

wrong answer 1st numbers differ - expected: '12', found: '11'