Submission #143973

#TimeUsernameProblemLanguageResultExecution timeMemory
143973tincamateiRectangles (IOI19_rect)C++14
10 / 100
2 ms396 KiB
#include "rect.h"

using namespace std;

bool goodRect(int i, int j, int exp) {
	return j - i - 1 > 0 && exp >= j - i - 1;
}

long long subtask5(const vector<vector<int> > &matr) {
	int N = matr.size(), M = matr[0].size();
	int exp = 0;
	int top = 0;
	long long rez = 0LL;
	vector<int> stiva(M);
	
	for(int c = 0; c < M; ++c) {
		bool eq = false;

		while(top > 0 && matr[1][c] >= matr[1][stiva[top - 1]]) {
			rez = rez + goodRect(stiva[top - 1], c, exp);
			if(matr[1][c] == matr[1][stiva[top - 1]])
				eq = true;
			--top;
		}

		if(!eq && top > 0)
			rez = rez + goodRect(stiva[top - 1], c, exp);
		stiva[top++] = c;

		if(matr[0][c] > matr[1][c] && matr[2][c] > matr[1][c])
			++exp;
		else
			exp = 0;
	}
	return rez;
}

long long count_rectangles(std::vector<std::vector<int> > a) {
	int N;
	N = a.size();

	if(N == 3)
		return subtask5(a);
	return 0;
}

Compilation message (stderr)

rect.cpp: In function 'long long int subtask5(const std::vector<std::vector<int> >&)':
rect.cpp:10:6: warning: unused variable 'N' [-Wunused-variable]
  int N = matr.size(), M = matr[0].size();
      ^
#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...