"Link" I am the link, point me:)
Test instructions
Exercises
In the end, there are only 3 cases of a,b,c
1,2,4
1,2,6
1,3,6
Then use Cnt[8] to count the number of occurrences of each number.
Output CNT[4] times 1,2,4
(if 1 or 2 is not enough, then no solution
Followed by
If the number of 6 and the number of 1 is different, then no solution
If the number of 2 times +3 is different from the number of 6 occurrences, then there is no solution.
Otherwise
Output CNT[2] a 1,2,6
CNT[3] A 1,3,6 is OK.
See if there's enough output for N/3 group.
If not enough, there is no solution (indicating that there are other useless numbers appearing
Code
#include <bits/stdc++.h> #define REP1 (I,A,B) for (int i = a;i <= b;i++) using namespace std;const int n = 1e5;int n , M;int cnt[10];vector<pair<int,pair<int,int> > > V;int Main () {ios::sync_with_stdio (0), Cin.tie (0), Cout.tie (0); CIN >> N; for (int i = 1;i <= n;i++) {int x; CIN >> X; cnt[x]++; } rep1 (I,1,cnt[4]) {v.push_back ({1,{2,4}}); if (cnt[1]==0) return cout<< "-1" <<endl,0; if (cnt[2]==0) return cout<< "-1" <<endl,0; cnt[1]--;cnt[2]--; n-=3; } Cnt[4] = 0; if (Cnt[1]!=cnt[6] | | | (cnt[2]+cnt[3])! = (Cnt[6])) {cout<< "-1" <<endl; return 0; } for (int i = 1;i <= cnt[2];i++) {v.push_back ({1,{2,6}}); n-=3; } for (int i = 1;i <= cnt[3];i++) {v.push_back ({1,{3,6}}); n-=3; } if (n!=0) return cout<<-1<<endl,0; for (auto temp:v) {cout<<temp.first<< '' <<temp.second.first<< ' <<temp.second.second<<endl; } return 0;}
"Codeforces 342A" Xenia and divisors