Submission #1263103

#TimeUsernameProblemLanguageResultExecution timeMemory
1263103_rain_Garden (JOI23_garden)C++20
6 / 100
41 ms4160 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define FOR(i , a , b) for(int i = (a) , _b = (b); i <= _b; ++i)
#define BIT(mask , x) (((mask) >> (x)) & (1))
#define MASK(x) ((LL)(1)<<(x))
#define sz(x) (int)(x).size()

template<class T1,class T2>	
	bool maximize(T1 &a , T2 b){
		if (a < b) return a = b , true; else return false;
	}
template<class T1,class T2>
	bool minimize(T1 &a, T2 b){
		if (a > b) return a = b , true; else return false;
	}
template<class T>
	void compress(vector<T>&data){
		sort(data.begin() , data.end());
		data.resize(unique(data.begin() , data.end()) - data.begin());
	}
template<class T1, class T2>	
	T2 Find(vector<T1>&data , T2 y){
		return upper_bound(data.begin() , data.end() , y) - data.begin();
	}
	
const int N = (int) 5e5;
const LL inf = (LL)1e18;
	int p[N + 2] , r[N + 2] , q[N + 2] , s[N + 2];
	int n , m , d;
	
namespace subtask1{
	bool check(){
		return d <= 100;
	}
	
	const int maxn = (int) 5000;
	vector<int> nen_x , nen_y;
	
	bool need[maxn + 2] = {};
	int used[maxn + 2] = {};
	int size = 0;
	
		bool intersec(int l1 , int r1 , int l2, int r2 , int x){
			if (l1 <= x && x <= r1) return true;
			if (l2 <= x && x <= r2) return true;
			return false;
		}
		
	void main_code(){
		
		LL ans = inf;
		
		for(int d1 = 0; d1 < d; ++d1){
			for(int d2 = 0; d2 < d; ++d2){
				for(int d3 = 0; d3 < d; ++d3) need[d3] = false;
				int l1 , r1 , l2 , r2;
				if (d1 <= d2) l1 = l2 = d1 , r1 = r2  = d2;
				else 
					if (d1 > d2) {
						l1 = d1 , r1 = d - 1 ;
						l2 = 0 , r2 = d2;
					}
					
				bool ok = true;
				for(int j = 1; j <= n; ++j){
					if (intersec(l1 , r1 , l2 , r2 , p[j]) == false) {
						ok = false; break;
					}
					need[q[j]] = true;
				}
				if (ok==false) continue;
				for(int j = 1; j <= m; ++j){
					if (intersec(l1 , r1 , l2 , r2 , r[j]) == false) need[s[j]] = true;
				}
				
				size = 0;
				int height = (d1 <= d2 ? d2 - d1 + 1 : d - d2 + d1 + 1);
				
				for(int j = 0; j < d; ++j){
					if (need[j]) used[size++] = j;
				}
				
				for(int j = 0; j < size; ++j) {
					int nxt = (j + size - 1) % size;
					int gap = (used[nxt] >= used[j] ? used[nxt] - used[j] + 1 : d - used[j] + used[nxt] + 1);
					minimize(ans , (LL)height * gap);
				}
			}
		}
		
		cout << ans;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0) ; cout.tie(0) ;
	#define name "main"
		if (fopen(name".inp","r")){
			freopen(name".inp","r",stdin);
			freopen(name".out","w",stdout);
		}
		
		cin >> n >> m >> d;
		for(int i = 1; i <= n; ++i) cin >> p[i] >> q[i];
		for(int i = 1; i <= m; ++i) cin >> r[i] >> s[i];
		if (subtask1::check()) return subtask1::main_code() , 0;	
	return 0;
}

Compilation message (stderr)

garden.cpp: In function 'int main()':
garden.cpp:102:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |                         freopen(name".inp","r",stdin);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
garden.cpp:103:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |                         freopen(name".out","w",stdout);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...