A rigid body sim where at the end all objects textures make out a picture?
The trick is simple: this is 'bake to the future'!

 

Once the simulation baked, go to the last frame and you'll know how to color the balls.

Here (but this is just an example as the materials could be totally different), I've assigned the object pass index knowing the positions at the last frame and used it to drive the color.