2020 Jan Platinum Problem 1 Cave Paintings

From Wiki
Revision as of 23:06, 11 June 2023 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Official Problem Statement[edit]

Cave Paintings

Problem statement:

Problem 996: Cave Paintings[edit]

You are given a cave with N (1 ≤ N ≤ 10,000) paintings. Each painting is a rectangular grid of size M × K (1 ≤ M, K ≤ 10,000). Each cell of the grid is either empty or contains a single color.

You are asked to find the maximum number of distinct colors that appear in any single painting.

Solution:

The solution to this problem is to use a two-dimensional array to store the colors of each painting. We can then iterate through the array and count the number of distinct colors in each painting. The maximum number of distinct colors is the answer.

C++ code example:

  1. include <iostream>
  2. include <vector>

using namespace std;

int main() {

   int N, M, K; 
   cin >> N >> M >> K; 
   
   vector<vector<vector<int>>> paintings(N, vector<vector<int>>(M, vector<int>(K))); 
   
   for (int i = 0; i < N; i++) 
   { 
       for (int j = 0; j < M; j++) 
       { 
           for (int k = 0; k < K; k++) 
           { 
               cin >> paintings[i][j][k]; 
           } 
       } 
   } 
   
   int maxColors = 0; 
   
   for (int i = 0; i < N; i++) 
   { 
       int colors = 0; 
       vector<bool> seen(10, false); 
       
       for (int j = 0; j < M; j++) 
       { 
           for (int k = 0; k < K; k++) 
           { 
               if (!seen[paintings[i][j][k]]) 
               { 
                   colors++; 
                   seen[paintings[i][j][k]] = true; 
               } 
           } 
       } 
       
       maxColors = max(maxColors, colors); 
   } 
   
   cout << maxColors << endl; 
   
   return 0; 

}