#include <iostream>
#include <vector>
using namespace std;
vector <char>decyzje;
bool u=0;
void probuj(int j,int z,int n){
if(u==1){return;}
if(j==0&&z==0&&u==0){
u=1;
for(int i=0;i<decyzje.size();i++){
cout<<decyzje[i];
}
return;
}
if(j<3||z<2){return;}
for(int i=0;i<n;i++){
if(j>=z){
decyzje.push_back('o');
probuj(j-6,z-2,n);
decyzje.pop_back();
decyzje.push_back('g');
probuj(j-5,z-3,n);
decyzje.pop_back();
}
decyzje.push_back('c');
probuj(j-4,z-4,n);
decyzje.pop_back();
if(j<z){
decyzje.push_back('a');
probuj(j-3,z-5,n);
decyzje.pop_back();}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,j=0,z=0;
cin>>n;
for(int i=0;i<8*n;i++){
char c;
cin>>c;
if(c=='1'){j++;}
if(c=='0'){z++;}
}
probuj(j,z,n);
if(u==0){
cout<<"NIE";
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <vector> using namespace std; vector <char>decyzje; bool u=0; void probuj(int j,int z,int n){ if(u==1){return;} if(j==0&&z==0&&u==0){ u=1; for(int i=0;i<decyzje.size();i++){ cout<<decyzje[i]; } return; } if(j<3||z<2){return;} for(int i=0;i<n;i++){ if(j>=z){ decyzje.push_back('o'); probuj(j-6,z-2,n); decyzje.pop_back(); decyzje.push_back('g'); probuj(j-5,z-3,n); decyzje.pop_back(); } decyzje.push_back('c'); probuj(j-4,z-4,n); decyzje.pop_back(); if(j<z){ decyzje.push_back('a'); probuj(j-3,z-5,n); decyzje.pop_back();} } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,j=0,z=0; cin>>n; for(int i=0;i<8*n;i++){ char c; cin>>c; if(c=='1'){j++;} if(c=='0'){z++;} } probuj(j,z,n); if(u==0){ cout<<"NIE"; } return 0; } |
English