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