fork download
  1. #include<stdio.h>
  2. #include<algorithm>
  3. using namespace std;
  4. int n,m,k,a[22][22],fail,q,i,j,M[22222][22],fi;
  5. char dump[1025];
  6. long long R;
  7. int main(){
  8. freopen("cowrun.in","r",stdin);
  9. freopen("cowrun.out","w",stdout);
  10. scanf("%d%d%d",&n,&m,&k);gets(dump);gets(dump);
  11. for(i=0;i<n;i++)for(j=0;j<8;j++)scanf("%d",&a[i][j]);
  12. for(i=0;i<(1<<n);i++)for(j=0;j<n;j++)if(i&(1<<j))M[i][j]=1;
  13. for(i=0;i<(1<<n);i++){ //FJ's choices
  14. fail=0;
  15. for(j=0;j<(1<<n);j++){
  16. R=0;
  17. for(q=0;q<n;q++){
  18. fi=((M[i][q]==0)<<2)+((M[j][q]==0)<<1);
  19. R+=(R*(long long)a[q][fi])+a[q][fi+1];if(R>=m)R%=m;
  20. }
  21. if(R>k&&(m-R)>k){fail=1;break;}
  22. }
  23. if(!fail){
  24. for(j=0;j<n;j++)if(i&(1<<j))putchar('T');else putchar('B');
  25. puts("");
  26. return 0;
  27. }
  28. }
  29. puts("something went wrong");
  30. return 0;
  31. }
  32.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty