RT,1RE4TLE真的搞不明白(RE是图中注释处爆了除0错误)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline ll read() {
register ll n = 0, s = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') s = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = (n << 1) + (n << 3) + c - '0';
c = getchar();
}
return s * n;
}
// P6523 「Wdoi-1」加密通信
ll ans[(int)1e5 + 10];
ll inp[(int)1e5 + 10];
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve() {
ll n, M;
n = read(), M = read();
memset(inp, 0, sizeof(inp));
memset(ans, 0, sizeof(ans));
bool mark = false; // inp[i]!=inp[i-1]
for (int i = 1; i < n; i++) {
inp[i] = read();
if (inp[i - 1] != inp[i] && inp[i - 1]) {
mark = true;
ans[i] = gcd(inp[i], inp[i - 1]);
if (ans[i] > M) {
cout << -1 << endl;
return;
}
for (int j = i - 1; j >= 1; j--) {
ans[j] = inp[j] / ans[j + 1];
if (ans[j] > M) {
cout << -1 << endl;
return;
}
}
}
if (mark) {
/*???????????????????????*/
ans[i + 1] = inp[i] / ans[i];
if (ans[i + 1] > M) {
cout << -1 << endl;
return;
}
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
cout << endl;
return;
};
int main() {
int T = read();
while (T--) {
solve();
}
return 0;
}