Submission #143714

# Submission time Handle Problem Language Result Execution time Memory
143714 2019-08-14T23:30:19 Z qkxwsm Rectangles (IOI19_rect) C++14
13 / 100
525 ms 147912 KB
#include "rect.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define y1 qkx
#define y2 wsm
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define MAXN 2513

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
vector<vi> grid;
int rt[MAXN][MAXN], dn[MAXN][MAXN];
int pref[MAXN][MAXN];
ll ans;

int psum(int x1, int x2, int y1, int y2)
{
	return pref[x2 + 1][y2 + 1] - pref[x1][y2 + 1] - pref[x2 + 1][y1] + pref[x1][y1];
}
ll count_rectangles(vector<vi> a)
{
	N = SZ(a); M = SZ(a[0]); grid = a; int mx = 0;
	FOR(i, 0, N) FOR(j, 0, M) ckmax(mx, grid[i][j]);
	if (mx <= 1)
	{
		FOR(i, 0, N)
		{
			FOR(j, 0, M)
			{
				pref[i + 1][j + 1] = pref[i][j + 1] + pref[i + 1][j] - pref[i][j] + grid[i][j];
			}
		}
		//for each square, compute the next 1 on the right
		FOR(i, 0, N)
		{
			rt[i][M] = M;
			FORD(j, M, 0)
			{
				rt[i][j] = (grid[i][j] ? j : rt[i][j + 1]);
			}
		}
		FOR(i, 0, M)
		{
			dn[N][i] = N;
			FORD(j, N, 0)
			{
				dn[j][i] = (grid[j][i] ? j : dn[j + 1][i]);
			}
		}
		FOR(x1, 1, N)
		{
			FOR(y1, 1, M)
			{
				if (grid[x1][y1]) continue;
				int y2 = rt[x1][y1] - 1, x2 = dn[x1][y1] - 1;
				if (x2 == N - 1 || y2 == M - 1) continue;
				// cerr << "CONSIDER " << x1 << ' ' << y1 << " -> " << x2 << ' ' << y2 << endl;
				if (psum(x1, x2, y1, y2) != 0) continue;
				if (psum(x1 - 1, x1 - 1, y1, y2) != (y2 - y1 + 1)) continue;
				if (psum(x2 + 1, x2 + 1, y1, y2) != (y2 - y1 + 1)) continue;
				if (psum(x1, x2, y1 - 1, y1 - 1) != (x2 - x1 + 1)) continue;
				if (psum(x1, x2, y2 + 1, y2 + 1) != (x2 - x1 + 1)) continue;
				ans++;
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 208 ms 70564 KB Output is correct
3 Correct 518 ms 147060 KB Output is correct
4 Correct 511 ms 147912 KB Output is correct
5 Correct 525 ms 147844 KB Output is correct
6 Correct 178 ms 73208 KB Output is correct
7 Correct 354 ms 143276 KB Output is correct
8 Correct 394 ms 147704 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -