Submission #1022027

# Submission time Handle Problem Language Result Execution time Memory
1022027 2024-07-13T09:14:22 Z mindiyak Rectangles (IOI19_rect) C++14
8 / 100
5000 ms 298900 KB
#include "rect.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<ld> vd;
typedef vector<long long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
 
int N,M;
vvi arr;
ll ans = 0;
set<pair<pi,pi>> visited;
vvi seg1(2502,vi(10005,0)),seg2(2502,vi(10005,0));

int make_seg1(int pos,int l,int r,int id){
	if(l==r){
		seg1[id][pos] = arr[l][id];
		return seg1[id][pos];
	}
	int mid = (l+r)/2;
	seg1[id][pos] = max(make_seg1(2*pos+1,l,mid,id),make_seg1(2*pos+2,mid+1,r,id));
	return seg1[id][pos];
}

int make_seg2(int pos,int l,int r,int id){
	if(l==r){
		seg2[id][pos] = arr[id][l];
		return seg2[id][pos];
	}
	int mid = (l+r)/2;
	seg2[id][pos] = max(make_seg2(2*pos+1,l,mid,id),make_seg2(2*pos+2,mid+1,r,id));
	return seg2[id][pos];
}

int get_seg1(int pos,int l,int r,int ql,int qr,int id){
	if(ql>r||qr<l)return 0;
	if(ql<=l && r<=qr)return seg1[id][pos];
	int mid = (l+r)/2;
	return max(get_seg1(2*pos+1,l,mid,ql,qr,id),get_seg1(2*pos+2,mid+1,r,ql,qr,id));
}
 
int get_seg2(int pos,int l,int r,int ql,int qr,int id){
	if(ql>r||qr<l)return 0;
	if(ql<=l && r<=qr)return seg2[id][pos];
	int mid = (l+r)/2;
	return max(get_seg2(2*pos+1,l,mid,ql,qr,id),get_seg2(2*pos+2,mid+1,r,ql,qr,id));
}
 
void dfs(int a,int b,int c,int d){
	if(c<a)swap(a,c);
	if(d<b)swap(b,d);
	if(visited.count({{a,b},{c,d}}))return;
	if(a == 0 || b == 0 || c == (N-1) || d == (M-1))return;
	visited.insert({{a,b},{c,d}});
	bool bad = false;
	// cout << "a " << a << " " << c << " " << b << " " << d  << endl; 
	FOR(i,a,c+1){
		int val = get_seg2(0,0,M-1,b,d,i);
		if(val >= arr[i][b-1])bad = true;
		if(val >= arr[i][d+1])bad = true;
		// cout << "b " << val << " " << arr[i][b-1] << " " << arr[i][b-1] << endl;
		// FOR(j,b,d+1){
		// 	if(arr[i][j] >= arr[i][b-1])bad = true;
		// 	if(arr[i][j] >= arr[i][d+1])bad = true;
		// 	if(arr[i][j] >= arr[a-1][j])bad = true;
		// 	if(arr[i][j] >= arr[c+1][j])bad = true;
		// 	if(bad)break;
		// }
	}
	FOR(j,b,d+1){
		int val = get_seg1(0,0,N-1,a,c,j);
		if(val >= arr[a-1][j])bad = true;
		if(val >= arr[c+1][j])bad = true;
		// cout << "b " << val << " " << arr[a-1][j] << " " << arr[c+1][j] << endl;
	}
	
	// cout << "c " << bad << endl << endl;
 
	// if(!bad)cout << a << " " << b << " " << c << " " << d  << " | " << wa << " " << wb << " " << wc << " " << wd << " - " << bad << endl;
 
	if(!bad)ans ++;
	dfs(a-1,b,c,d);
	dfs(a,b-1,c,d);
	dfs(a,b,c+1,d);
	dfs(a,b,c,d+1);
}

//seg1 V
//seg2 >

ll count_rectangles(vvi a) {
	N = a.size();M = a[0].size();
	// cout << endl;
	arr = a;
	FOR(i,0,M){
		make_seg1(0,0,N-1,i);
	}
	FOR(i,0,N){
		make_seg2(0,0,M-1,i);
	}
	// FOR(i,0,M){
	// 	cout << get_seg1(0,0,N-1,0,0,i) << endl;
	// }
	// cout << "#" << endl;
	// FOR(i,0,N){
	// 	cout << get_seg2(0,0,M-1,0,0,i) << endl;
	// }
	// cout << "#" << endl;
	// FOR(i,0,N){
	// 	FOR(j,0,4*M){
	// 		cout << seg2[i][j] << " ";
	// 	}cout << endl;
	// }
	FOR(i,1,N-1){
		FOR(j,1,M-1){
			dfs(i,j,i,j);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 89 ms 196492 KB Output is correct
2 Correct 268 ms 206652 KB Output is correct
3 Correct 258 ms 206672 KB Output is correct
4 Correct 260 ms 206784 KB Output is correct
5 Correct 291 ms 206876 KB Output is correct
6 Correct 260 ms 206732 KB Output is correct
7 Correct 115 ms 198208 KB Output is correct
8 Correct 111 ms 197948 KB Output is correct
9 Correct 287 ms 206672 KB Output is correct
10 Correct 264 ms 206676 KB Output is correct
11 Correct 258 ms 206752 KB Output is correct
12 Correct 267 ms 206680 KB Output is correct
13 Correct 93 ms 196508 KB Output is correct
14 Correct 91 ms 196436 KB Output is correct
15 Correct 95 ms 196432 KB Output is correct
16 Correct 94 ms 196436 KB Output is correct
17 Correct 95 ms 196436 KB Output is correct
18 Correct 94 ms 196444 KB Output is correct
19 Correct 271 ms 206816 KB Output is correct
20 Correct 123 ms 198768 KB Output is correct
21 Correct 92 ms 196432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 196492 KB Output is correct
2 Correct 268 ms 206652 KB Output is correct
3 Correct 258 ms 206672 KB Output is correct
4 Correct 260 ms 206784 KB Output is correct
5 Correct 291 ms 206876 KB Output is correct
6 Correct 260 ms 206732 KB Output is correct
7 Correct 115 ms 198208 KB Output is correct
8 Correct 111 ms 197948 KB Output is correct
9 Correct 287 ms 206672 KB Output is correct
10 Correct 264 ms 206676 KB Output is correct
11 Correct 258 ms 206752 KB Output is correct
12 Correct 267 ms 206680 KB Output is correct
13 Correct 93 ms 196508 KB Output is correct
14 Correct 91 ms 196436 KB Output is correct
15 Correct 95 ms 196432 KB Output is correct
16 Correct 94 ms 196436 KB Output is correct
17 Correct 95 ms 196436 KB Output is correct
18 Correct 94 ms 196444 KB Output is correct
19 Correct 271 ms 206816 KB Output is correct
20 Correct 123 ms 198768 KB Output is correct
21 Correct 92 ms 196432 KB Output is correct
22 Execution timed out 5057 ms 298900 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 196492 KB Output is correct
2 Correct 268 ms 206652 KB Output is correct
3 Correct 258 ms 206672 KB Output is correct
4 Correct 260 ms 206784 KB Output is correct
5 Correct 291 ms 206876 KB Output is correct
6 Correct 260 ms 206732 KB Output is correct
7 Correct 115 ms 198208 KB Output is correct
8 Correct 111 ms 197948 KB Output is correct
9 Correct 287 ms 206672 KB Output is correct
10 Correct 264 ms 206676 KB Output is correct
11 Correct 258 ms 206752 KB Output is correct
12 Correct 267 ms 206680 KB Output is correct
13 Correct 93 ms 196508 KB Output is correct
14 Correct 91 ms 196436 KB Output is correct
15 Correct 95 ms 196432 KB Output is correct
16 Correct 94 ms 196436 KB Output is correct
17 Execution timed out 5057 ms 298900 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 196492 KB Output is correct
2 Correct 268 ms 206652 KB Output is correct
3 Correct 258 ms 206672 KB Output is correct
4 Correct 260 ms 206784 KB Output is correct
5 Correct 291 ms 206876 KB Output is correct
6 Correct 260 ms 206732 KB Output is correct
7 Correct 115 ms 198208 KB Output is correct
8 Correct 111 ms 197948 KB Output is correct
9 Correct 287 ms 206672 KB Output is correct
10 Correct 264 ms 206676 KB Output is correct
11 Correct 258 ms 206752 KB Output is correct
12 Correct 267 ms 206680 KB Output is correct
13 Correct 93 ms 196508 KB Output is correct
14 Correct 91 ms 196436 KB Output is correct
15 Correct 95 ms 196432 KB Output is correct
16 Correct 94 ms 196436 KB Output is correct
17 Execution timed out 5057 ms 298900 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5037 ms 233040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 196436 KB Output is correct
2 Correct 94 ms 196444 KB Output is correct
3 Correct 271 ms 206816 KB Output is correct
4 Correct 123 ms 198768 KB Output is correct
5 Correct 92 ms 196432 KB Output is correct
6 Correct 99 ms 196560 KB Output is correct
7 Execution timed out 5056 ms 237040 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 196492 KB Output is correct
2 Correct 268 ms 206652 KB Output is correct
3 Correct 258 ms 206672 KB Output is correct
4 Correct 260 ms 206784 KB Output is correct
5 Correct 291 ms 206876 KB Output is correct
6 Correct 260 ms 206732 KB Output is correct
7 Correct 115 ms 198208 KB Output is correct
8 Correct 111 ms 197948 KB Output is correct
9 Correct 287 ms 206672 KB Output is correct
10 Correct 264 ms 206676 KB Output is correct
11 Correct 258 ms 206752 KB Output is correct
12 Correct 267 ms 206680 KB Output is correct
13 Correct 93 ms 196508 KB Output is correct
14 Correct 91 ms 196436 KB Output is correct
15 Correct 95 ms 196432 KB Output is correct
16 Correct 94 ms 196436 KB Output is correct
17 Execution timed out 5057 ms 298900 KB Time limit exceeded
18 Halted 0 ms 0 KB -