QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214910#7560. Computer Networkb2ogeymanWA 0ms3720kbC++171.4kb2023-10-15 01:19:182023-10-15 01:19:18

Judging History

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

  • [2023-10-15 01:19:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2023-10-15 01:19:18]
  • 提交

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;
}

详细

Test #1:

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

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: 3676kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

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

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

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

input:

1
249912
43

output:

35

result:

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