amcbn

USACO 2017 US Open Contest, Bronze - Problem 3. Modern Art

Nov 8th, 2025
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("art.in");
  4. ofstream fout("art.out");
  5.  
  6. const int nmax = 10;
  7. int n;
  8. int c[nmax + 1][nmax + 1];
  9. struct BoundingBox {
  10.     int xmin = 1e9, ymin = 1e9;
  11.     int xmax = 0, ymax = 0;
  12. } bb[nmax + 1];
  13.  
  14. void update(BoundingBox& bb, int x, int y) {
  15.     bb.xmin = min(bb.xmin, x);
  16.     bb.ymin = min(bb.ymin, y);
  17.     bb.xmax = max(bb.xmax, x);
  18.     bb.ymax = max(bb.ymax, y);
  19. }
  20.  
  21. bool ok[nmax + 1];
  22.  
  23. int main() {
  24.     fin >> n;
  25.     for (int i = 1; i <= n; ++i) {
  26.         for (int j = 1; j <= n; ++j) {
  27.             char ch;
  28.             fin >> ch;
  29.             c[i][j] = ch - '0';
  30.             if (c[i][j] == 0) {
  31.                 continue;
  32.             }
  33.             ok[c[i][j]] = true;
  34.             update(bb[c[i][j]], i, j);
  35.         }
  36.     }
  37.     for (int i = 1; i <= n; ++i) {
  38.         for (int j = 1; j <= n; ++j) {
  39.             if (c[i][j] == 0) {
  40.                 continue;
  41.             }
  42.             for (int k = 1; k <= 9; ++k) {
  43.                 if (k == c[i][j]) {
  44.                     continue;
  45.                 }
  46.                 // vreau sa vad daca (i, j) este inclusa in bounding boxul culorii k
  47.                 if (bb[k].xmin <= i && i <= bb[k].xmax && bb[k].ymin <= j && j <= bb[k].ymax) {
  48.                     // culoarea c[i][j] a fost pusa dupa culoarea k
  49.                     ok[c[i][j]] = false;
  50.                 }
  51.             }
  52.         }
  53.     }
  54.     fout << count(ok + 1, ok + 11, true);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment