Submission #145539

# Submission time Handle Problem Language Result Execution time Memory
145539 2019-08-20T11:12:46 Z peijar Bob (COCI14_bob) C++14
12 / 120
182 ms 24256 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXN = 1e3;

ll height[MAXN][MAXN];
ll lowest[MAXN][MAXN];
ll largest[MAXN][MAXN];
int N,M;

int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	read2(N,M);
	FOR(i,0,N) FOR(j,0,M)
		read(height[i][j]);
	
	for (int col(0); col < M; ++col)
	{
		lowest[N-1][col] = 1;
		for (int line(N-2); line >= 0; --line)
		{
			if (height[line][col] == height[line+1][col])
				lowest[line][col] = lowest[line+1][col]+1;
			else
				lowest[line][col] = 1;
		}
	}

	for (int line(0); line < N; ++line)
	{
		largest[line][0] = 1;
		for (int col(1); col < M; ++col)
		{
			if (height[line][col-1] == height[line][col] && lowest[line][col] == lowest[line][col-1])
				largest[line][col] = 1 + largest[line][col-1];
			else
				largest[line][col] = 1;
		}
	}

	ll ans(0);

	for (int line(0); line < N; ++line)
	{
		int prev_h = -1;
		ll low = lowest[line][M-1];
		ll wid = 0;
		int col = M-1;
		while (col >= 0)
		{
			ans += lowest[line][col] * ((largest[line][col] * (largest[line][col] + 1)) / 2);
			low = min(low, lowest[line][col]);
			if (prev_h == height[line][col])
				ans += largest[line][col] * wid * low;
			else
			{
				prev_h = height[line][col];
				wid = 0;
				low = lowest[line][col];
			}
			wid += largest[line][col];
			col -= largest[line][col];
		}
	}

	pnl(ans);
}

# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 12024 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 12016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 12080 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 12120 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 23860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 182 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 182 ms 24256 KB Output isn't correct
2 Halted 0 ms 0 KB -