답안 #672198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672198 2022-12-15T03:43:08 Z amunduzbaev Cultivation (JOI17_cultivation) C++17
45 / 100
379 ms 2512 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;
#define int ll

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m; cin >> n >> m;
	int sz; cin >> sz;
	vector<int> x(sz), y(sz), t;
	for(int i=0;i<sz;i++){
		cin >> x[i] >> y[i];
	} 
	
	t = x;
	sort(t.begin(), t.end());
	t.erase(unique(t.begin(), t.end()), t.end());
	vector<int> used(t.size());
	
	vector<int> id(sz);
	for(int i=0;i<sz;i++){
		id[i] = lower_bound(t.begin(), t.end(), x[i]) - t.begin() + 1;
	}
	
	int res = 2 * (n + m);
	set<int> don;
	auto check = [&](int d){
		if(don.count(d)) return;
		don.insert(d);
		vector<ar<int, 2>> tot;
		for(int i=0;i<sz;i++){
			//~ cout<<max(1LL, y[i] - w)<<" "<<min(y[i] + e, m)<<"\n";
			tot.push_back({y[i], id[i]});
			tot.push_back({y[i] + d + 1, -id[i]});
		}
		sort(tot.begin(), tot.end());
		vector<int> v, is;
		vector<ar<int, 3>> Mn;
		for(int i=0;i<(int)tot.size();){
			int j = i;
			while(j < (int)tot.size() && tot[j][0] == tot[i][0]){
				if(tot[j][1] > 0) used[tot[j][1] - 1]++;
				else used[-tot[j][1] - 1]--;
				j++;
			}
			
			//~ cout<<tot[i][0]<<" : ";
			int mnl = 0, mn = 0;
			int last = -1;
			for(int i=0;i<(int)t.size();i++){
				if(!used[i]) continue;
				if(~last) mn = max(mn, t[i] - t[last] - 1);
				else mnl = t[i] - 1;
				last = i;
			}
			v.push_back(tot[i][0]);
			if(last == -1){
				Mn.push_back({0, 0, 0});
				is.push_back(1);
			} else {
				Mn.push_back({mnl, n - t[last], mn});
				is.push_back(0);
			}
			
			i = j;
		}
		
		for(int i=0;i + 1 < (int)v.size();i++){
			int mnl = 0, mnr = 0, mn = 0;
			for(int j=i;j + 1 < (int)v.size();j++){
				if(is[j]) break;
				mnl = max(mnl, Mn[j][0]);
				mnr = max(mnr, Mn[j][1]);
				mn = max(mn, Mn[j][2]);
				if(v[j + 1] - v[i] >= m){
					res = min(res, d + max(mnl + mnr, mn));
				}
			}
		}
	};
	
	vector<int> tmp;
	
	for(int i=0;i<sz;i++){
		for(int j=0;j<sz;j++){
			//~ check(y[i] - 1 + m - y[j]);
			tmp.push_back(y[i] - 1 + m - y[j]);
		}
		
		for(int k=0;k<sz;k++){
			if(y[i] >= y[k]) continue;
			//~ check(y[k] - y[i] - 1);
			tmp.push_back(y[k] - y[i] - 1);
		}
	}
	
	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	shuffle(tmp.begin(), tmp.end(), rng);
	tmp.resize(min((int)tmp.size(), 1000ll));
	for(auto x : tmp) check(x);
	
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 6 ms 980 KB Output is correct
25 Correct 5 ms 856 KB Output is correct
26 Correct 12 ms 2508 KB Output is correct
27 Correct 11 ms 2508 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 10 ms 2508 KB Output is correct
30 Correct 12 ms 2508 KB Output is correct
31 Correct 11 ms 2508 KB Output is correct
32 Correct 11 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 6 ms 980 KB Output is correct
25 Correct 5 ms 856 KB Output is correct
26 Correct 12 ms 2508 KB Output is correct
27 Correct 11 ms 2508 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 10 ms 2508 KB Output is correct
30 Correct 12 ms 2508 KB Output is correct
31 Correct 11 ms 2508 KB Output is correct
32 Correct 11 ms 2508 KB Output is correct
33 Incorrect 379 ms 2512 KB Output isn't correct
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 7 ms 332 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 7 ms 352 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 7 ms 364 KB Output is correct
17 Correct 7 ms 364 KB Output is correct
18 Correct 7 ms 340 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 7 ms 332 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 7 ms 352 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 7 ms 364 KB Output is correct
17 Correct 7 ms 364 KB Output is correct
18 Correct 7 ms 340 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Incorrect 76 ms 548 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 6 ms 980 KB Output is correct
25 Correct 5 ms 856 KB Output is correct
26 Correct 12 ms 2508 KB Output is correct
27 Correct 11 ms 2508 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 10 ms 2508 KB Output is correct
30 Correct 12 ms 2508 KB Output is correct
31 Correct 11 ms 2508 KB Output is correct
32 Correct 11 ms 2508 KB Output is correct
33 Incorrect 379 ms 2512 KB Output isn't correct
34 Halted 0 ms 0 KB -