//Jakub Rozek
//Zaklocenia
//czas: n
//pammiec: n
#include "bits/stdc++.h"
using namespace std;
int n,j,z;
string s;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>s;
for(int i=s.size()-1; i>=0; --i)
{
if(s[i]=='1') ++j;
else ++z;
}
if(j>n*6 || z>n*5)
{
cout<<"NIE";
return 0;
}
while(j>=z+4)
{
cout<<"w";
j-=6;
z-=2;
}
while(j>z)
{
cout<<"k";
j-=5;
z-=3;
}
while(z>j)
{
cout<<"a";
j-=3;
z-=5;
}
while(j)
{
cout<<"c";
j-=4;
z-=4;
}
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 53 54 55 56 | //Jakub Rozek //Zaklocenia //czas: n //pammiec: n #include "bits/stdc++.h" using namespace std; int n,j,z; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>s; for(int i=s.size()-1; i>=0; --i) { if(s[i]=='1') ++j; else ++z; } if(j>n*6 || z>n*5) { cout<<"NIE"; return 0; } while(j>=z+4) { cout<<"w"; j-=6; z-=2; } while(j>z) { cout<<"k"; j-=5; z-=3; } while(z>j) { cout<<"a"; j-=3; z-=5; } while(j) { cout<<"c"; j-=4; z-=4; } return 0; } |
English