感觉这题应该不会爆,但我把以下代码换成 python 就过了(C++ 打了高精还是没过)。
#include <bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n, k, a;
signed main() {
cin >> t;
while (t--) {
int p, f = 1, s = 2;
cin >> n >> k;
for (int i = 1; i <= k - 1; ++i) {
cin >> a;
if (a == 1) {
f = s;
s = f + (1 << i);
}
if (a == 2) {
s = f + (1 << i);
}
}
cin >> a;
if (a == 1) cout << s << '\n';
else cout << f << '\n';
}
}
t = int(input())
for i in range(t) :
p = input().split()
n = int(p[0])
k = int(p[1])
a = input().split()
f = 1
s = 2
for j in range(k - 1) :
if int(a[j]) == 1 :
f = s
s = f + (1 << (j + 1))
else :
s = f + (1 << (j + 1))
if int(a[k - 1]) == 1 : print(s)
else : print(f)