Codeforces Round 1023 (Div. 2)
Dashboard - Codeforces Round 1023 (Div. 2) - Codeforces
一个构造问题,我把最大的数放在一个数组,其余数放在另一个数组,就能保证gcd不同
来看代码:
#include <bits/stdc++.h>
using namespace std;int main() {int t;cin >> t;while (t--) {int n;cin >> n;int maxx = -1;int cursor = 0;int pre = 0;int flag = 0;for (int i = 0; i < n; i++){int now;cin >> now;if (i > 0&&pre!=now){flag = 1;}if (now > maxx){maxx = now;cursor = i;}pre = now;}if (flag == 0){cout << "NO";}else{cout << "YES" << "\n";for (int i = 0; i < n; i++){if (i == cursor){cout << 1 << " ";}else{cout << 2 << " ";}}}cout << "\n";}return 0;
}