QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214898#7560. Computer NetworkTheOneYouWant#WA 0ms3684kbC++171.4kb2023-10-15 01:08:512023-10-15 01:08:51

Judging History

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

  • [2023-10-15 01:08:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2023-10-15 01:08:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define ln '\n'
#define int ll
const int INF = 1e9+7;

int n;
vi a, aa, b;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    a.resize(n);
    aa.resize(n);
    b.resize(n);
    rep(i, 0, n)
        cin >> aa[i];
    rep(i, 0, n)
        cin >> b[i];
    int ans = INF;
    rep(k, 0, 32) {
        rep(i, 0, n)
            a[i] = aa[i];
        bool flag = false;
        rep(i, 0, n)
            if(a[i] >= (b[i]+1)*(1LL << k))
                flag = true;
        if(flag)
            continue;
        int m = (1LL << k);
        int cur = 0;
        while(m) {
            int need = INF;
            rep(i, 0, n)
                need = min(need, (b[i]*(1LL << k) + (1LL << k) - 1 - a[i])/m);
            rep(i, 0, n)
                a[i] += need*m;
            cur += need;
            m >>= 1;
        }
        bool good = true;
        rep(i, 0, n) {
            assert(a[i] < (b[i]+1)*(1LL << k));
            if(a[i] < b[i]*(1LL << k))
                good=false;
        }
        if(good)
            ans = min(ans, cur + k);
    }
    if(ans == INF)
        cout << -1 << ln;
    else 
        cout << ans << ln;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3680kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

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

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3684kb

input:

1
249912
43

output:

35

result:

wrong answer 1st numbers differ - expected: '26', found: '35'