Submission #328763

#TimeUsernameProblemLanguageResultExecution timeMemory
328763VROOM_VARUNRectangles (IOI19_rect)C++14
8 / 100
5053 ms29644 KiB
/*
ID: varunra2
LANG: C++
TASK: rectangles
*/

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

bool f(int a, VI b) { return a >= *min_element(all(b)); }

bool ok(VVI vals) {
  if (sz(vals) < 3) return false;
  if (sz(vals[0]) < 3) return false;
  int n = sz(vals);
  int m = sz(vals[0]);
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      int val = vals[i][j];
      int v1 = vals[0][j];
      int v2 = vals[n - 1][j];
      int v3 = vals[i][0];
      int v4 = vals[i][m - 1];
      if (f(val, {v1, v2, v3, v4})) return false;
    }
  }
  return true;
}

VVI get(VVI& vals, int l, int r, int s, int e) {
  VVI ret(e - s + 1, VI(r - l + 1));
  for (int i = s; i <= e; i++) {
    for (int j = l; j <= r; j++) {
      ret[i - s][j - l] = vals[i][j];
    }
  }
  return ret;
}

ll count_rectangles(VVI vals) {
  int ret = 0;
  int bad = 0;
  for (int i = 0; i < sz(vals); i++) {
    for (int j = 0; j < sz(vals[0]); j++) {
      for (int k = i; k < sz(vals); k++) {
        for (int l = j; l < sz(vals[0]); l++) {
          int cur = ok(get(vals, j, l, i, k));
          if (cur)
            ret++;
          else
            bad++;
          if (cur) debug(i, j, k, l);
        }
      }
    }
  }
  return ret;
}

Compilation message (stderr)

rect.cpp: In function 'll count_rectangles(VVI)':
rect.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
rect.cpp:97:20: note: in expansion of macro 'debug'
   97 |           if (cur) debug(i, j, k, l);
      |                    ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...