#include #include int main() { gdImagePtr img; int color[256]; int color_count; int color_red, color_green, color_blue; int i, x, y; int x_size, y_size; scanf( "%i %i %i", &x_size, &y_size, &color_count ); img = gdImageCreate( x_size, y_size ); for( i = 0; i < color_count; i ++ ) { scanf( "%i %i %i", &color_red, &color_green, &color_blue ); color[i] = gdImageColorAllocate( img, color_red, color_blue, color_green ); } for( y = 0; y < y_size; y ++ ) { for( x = 0; x < x_size; x ++ ) { scanf( "%i", &i ); gdImageSetPixel( img, x, y, color[i] ); } } gdImageGif( img, stdout ); gdImageDestroy( img ); }