给定大小为 -1
。
感觉这题的难度感觉完全不够 Ex,也完全不够紫,说这是 D 题我都信。。。
首先考虑转化两种操作,不难想到可以认为是在二进制中,前者即为右移一位,后者为左移一位。或者说前者是在二进制的末尾追加一个
综上我们题意转化为了,操作可以在
思路明显且代码实现极为简单。
xxxxxxxxxx
591
2
3
4
5
6
7
8
9
10
11using namespace std;
12
13mt19937 rnd(random_device{}());
14int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
15bool rnddd(int x){return rndd(1, 100) <= x;}
16
17typedef unsigned int uint;
18typedef unsigned long long unll;
19typedef long long ll;
20typedef long double ld;
21
22template < typename T = int >
23inline T read(void);
24
25int N;
26ll ans(0);
27priority_queue < int, vector < int >, less < int > > a, b;
28
29int main(){
30 N = read();
31 for(int i = 1; i <= N; ++i)a.push(read());
32 for(int i = 1; i <= N; ++i)b.push(read());
33 while(!a.empty() && !b.empty()){
34 int x = a.top(), y = b.top(); a.pop(), b.pop();
35 if(x > y)a.push(x >> 1), b.push(y), ++ans;
36 else if(x < y){
37 if(y & 1)printf("-1\n"), exit(0);
38 else a.push(x), b.push(y >> 1), ++ans;
39 }
40 }printf("%lld\n", ans);
41 fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
42 return 0;
43}
44
45template < typename T >
46inline T read(void){
47 T ret(0);
48 int flag(1);
49 char c = getchar();
50 while(c != '-' && !isdigit(c))c = getchar();
51 if(c == '-')flag = -1, c = getchar();
52 while(isdigit(c)){
53 ret *= 10;
54 ret += int(c - '0');
55 c = getchar();
56 }
57 ret *= flag;
58 return ret;
59}
update-2022_12_06 初稿