fork download
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #define ll long long
  4. using namespace std;
  5. int n,m,k,x,j,i,t[502],vt[502];
  6. string s,st[501],a;
  7. int main()
  8. {
  9. cin>>m>>k>>x;
  10. //cin>>s;
  11. for (i=1;i<=m;i++)
  12. {
  13. cin>>a;
  14. sort(a.begin(),a.end());
  15. for (j=0;j<a.size();j++)
  16. if (a[j]!=a[j+1]) st[i]+=a[j];
  17. cout<<st[i]<<" ";
  18. }
  19. t[m+1]=1;
  20. for (i=m;i>=1;i--)
  21. {
  22. t[i]=t[i+1]*st[i].size();
  23.  
  24. }
  25. for (i=1;i<=m+1;i++)cout<<t[i]<<" ";
  26. cout<<endl;
  27. if (t[1]==x)
  28. {
  29. for (i=1;i<=m;i++) vt[i]=st[i].size();
  30. }
  31. else
  32. {
  33. i=1;
  34. while (x>0)
  35. {
  36. if (x>=t[i+1])
  37. {
  38. vt[i]=x/t[i+1];
  39. if (x%t[i+1]!=0)
  40. {
  41. x=x%t[i+1];
  42. vt[i]++;
  43. }
  44. else
  45. {
  46. for (j=i+1;j<=m;j++) vt[j]=st[j].size();
  47. x=0;
  48. }
  49. }
  50. else vt[i]=1;
  51. i++;
  52. }
  53. }
  54. for (i=1;i<=m;i++) cout<<vt[i]<<" ";
  55.  
  56. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1