#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<limits.h>
char dec[]={'B','C','G'};
char binComb[5],minComb[5];
unsigned long long B[3],G[3],C[3],min=ULLONG_MAX,moves,tmpSum,tmpMin=ULLONG_MAX,minFind,inpMin;
unsigned long long *ptr[24];
int i,ii,j,k,iFind;
long long tmpMax;
inline unsigned long long calcMoves(char color,int pos){
tmpSum=0;
for(ii=0;ii<3;ii++){
if(ii==pos) continue;
tmpSum = tmpSum + ptr[color-'0'][ii];
}
return tmpSum;
}
inline unsigned long long minx(){
minFind=ULLONG_MAX;
for(iFind=0;iFind<3;iFind++){
if(B[iFind]<minFind){minFind=B[iFind];}
if(G[iFind]<minFind){minFind=G[iFind];}
if(C[iFind]<minFind){minFind=C[iFind];}
}
return minFind;
}
int main()
{
ptr['B'-'0']=B;
ptr['G'-'0']=G;
ptr['C'-'0']=C;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
while(scanf("%llu%llu%llu%llu%llu%llu%llu%llu%llu",&B[0],&G[0],&C[0],&B[1],&G[1],&C[1],&B[2],&G[2],&C[2])==9){
inpMin=minx();
if(inpMin>0){
for(iFind=0;iFind<3;iFind++){
B[iFind]-=inpMin;
G[iFind]-=inpMin;
C[iFind]-=inpMin;
}
}
min=ULLONG_MAX;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
for(k=0;k<3;k++){
if(i==j || i==k || j==k) continue;
sprintf(binComb,"%c%c%c",dec[i],dec[j],dec[k]);
moves=calcMoves(dec[i],0)+calcMoves(dec[j],1)+calcMoves(dec[k],2);
if(moves<min) { min=moves;strcpy(minComb,binComb); }
}
}
}
if(inpMin>0) min+=(inpMin*2*3);
printf("%s %llu\n",minComb,min);
}
return 0;
}
No comments:
Post a Comment