답안 #414132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414132 2021-05-30T06:24:29 Z amoo_safar Cultivation (JOI17_cultivation) C++17
0 / 100
793 ms 262148 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<int, int> pii;

const ll Mod = 1000000007LL;
const int N = 3e2 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int n, R, C;
pii A[N];

// 0, x, y -> C + R < x -> y
// 1, x, y -> C < x -> y
// 2, x, y -> R < x -> y
typedef pair<int, pii> Query;
vector<Query> Q;

void Check(int l, int r){
	int ln = r - l - 1;
	vector<int> V;
	for(int k = 1; k <= n; k++){
		if(l < A[k].F && A[k].F < r)
			V.pb(A[k].S);
	}
	sort(all(V));
	if(!V.empty() && V[0] > 1)
		Q.pb({1, {V[0] - 1, ln}});
	if(!V.empty() && V.back() < C)
		Q.pb({2, {C - V.back(), ln}});
	for(int i = 0; i + 1 < (int) V.size(); i++){
		if(0 < V[i + 1] - V[i] - 1)
			Q.pb({0, {V[i + 1] - V[i] - 1, ln}});
	}
	if(V.empty())
		Q.pb({1, {C, ln}});
}

int ans[N][N]; // C R

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> R >> C >> n;
	for(int i = 1; i <= n; i++){
		cin >> A[i].F >> A[i].S;
	}
	sort(A + 1, A + n + 1);
	vector<int> V;
	sort(all(V));
	for(int i = 1; i <= n; i++) V.pb(A[i].S);
	int mn_S = 0;
	for(int i = 0; i < n; i++)
		mn_S = max(mn_S, V[i + 1] - V[i] - 1);
	// Check(0, R + 1);
	int mx = (A[1].F - 1) + (R - A[n].F);
	
	// for(int i = 1; i <= n; i++){
	// 	Check(0, A[i].F);
	// 	Check(A[i].F, R + 1);
	// 	for(int j = i + 1; j <= n; j++){
	// 		if(A[j].F - 1 <= A[i].F) continue;
	// 		Check(A[i].F, A[j].F);
	// 	}
	// }
	for(int i = 0; i <= R; i++){
		for(int j = i + 2; j <= R + 1; j++)
			Check(i, j);
	}
	int mn_C = C, mn_R = C;
	for(int i = 1; i <= n; i++)
		mn_C = min(mn_C, A[i].S - 1), mn_R = min(mn_R, C - A[i].S);
	for(int i = 0; i < C; i++)
		for(int j = 0; j < C; j++)
			ans[i][j] = mx;

	for(auto [ty, el] : Q){
		// cerr << "!!! " << ty << ' ' << el.F << " " << el.S << '\n';
		if(ty == 0){
			for(int i = 0; i < C; i++)
				for(int j = 0; j < C; j++)
					if(i + j < el.F)
						ans[i][j] = max(ans[i][j], el.S);
		} else if (ty == 1){
			for(int i = 0; i < C; i++)
				for(int j = 0; j < C; j++)
					if(i < el.F)
						ans[i][j] = max(ans[i][j], el.S);
		} else {
			for(int i = 0; i < C; i++)
				for(int j = 0; j < C; j++)
					if(j < el.F)
						ans[i][j] = max(ans[i][j], el.S);
		}
	}

	int res = R + C;
	for(int i = mn_C; i < C; i++){
		for(int j = mn_R; j < C; j++){
			if(i + j >= mn_S)
				res = min(res, ans[i][j] + i + j);
		}
	}
	cout << res << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 793 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 793 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -