답안 #145522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145522 2019-08-20T10:35:46 Z peijar Bob (COCI14_bob) C++14
120 / 120
617 ms 17940 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;

int height[MAXN][MAXN];
int lowest[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;
		}
	}

	ll ans(0);
	for (int line(0); line < N; ++line)
		for (int col(0); col < M; ++col)
		{
			int low = lowest[line][col];
			int k = 0;
			while (col + k < M && height[line][col + k] == height[line][col])
			{
				low = min(low, lowest[line][col+k++]);
				ans += low;
			}
		}
		pnl(ans);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 5368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 15004 KB Output is correct
2 Correct 564 ms 10168 KB Output is correct
3 Correct 617 ms 10164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 17940 KB Output is correct
2 Correct 288 ms 10232 KB Output is correct
3 Correct 616 ms 10244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 17876 KB Output is correct
2 Correct 615 ms 10220 KB Output is correct
3 Correct 613 ms 10156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 17920 KB Output is correct
2 Correct 594 ms 10232 KB Output is correct
3 Correct 615 ms 10104 KB Output is correct