Submission #519109

# Submission time Handle Problem Language Result Execution time Memory
519109 2022-01-25T16:39:15 Z Antekb Cultivation (JOI17_cultivation) C++14
80 / 100
2000 ms 3192 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb(x) push_back(x)
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)

using namespace std;

///~~~~~~~~~~~~~~~~~~~~~~~~~~

void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);

///~~~~~~~~~~~~~~~~~~~~~~~~~

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef unsigned int uint;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=305, INF=1e9+5, mod=1e9+7;
pair<int, int> r[N][N];
uint len[N][N];
int tim[N][N];
uint X[N];
int Y[N];
uint M[N];
pair<int, int> find(pair<int, int> x){
	if(r[x.st][x.nd]==x)return x;
	return r[x.st][x.nd]=find(r[x.st][x.nd]);
}
void Union(int a, int b){
	pii u=find(mp(a, b));
	if(a==0){
		len[u.st][u.nd]=2*INF;
		return;
	}
	pii v=find(mp(a-1, b));
	assert(u!=v);
	r[v.st][v.nd]=u;
	len[u.st][u.nd]+=len[v.st][v.nd];
}
int main(){
	//BOOST;
	int n, w, h;
	cin>>h>>w>>n;
	//assert(n<=250);
	vii pts(n);
	for(pii &i:pts)cin>>i.st>>i.nd, i.st--, i.nd--;
	map<int, int> cx, cy;
	for(int i=0; i<pts.size(); i++){
		cx[pts[i].st]=1;
		cy[pts[i].nd]=1;
	}
	int wsk=0;
	for(auto &i:cx){
		X[wsk]=i.st;
		i.nd=wsk++;
	}
	wsk=0;
	for(auto &i:cy){
		Y[wsk]=i.st;
		i.nd=wsk++;
	}
	uint ans=2*INF;
	X[cx.size()]=h;
	for(int y=0; y<cy.size(); y++){
		for(int i=0; i<cx.size(); i++){
			for(int j=0; j<cy.size(); j++){
				tim[i][j]=2*INF;
			}
			//r[i][wsk]=mp(i, wsk);
		}
		Y[cy.size()]=Y[y]+w;
		deb(y);
		for(int i=0; i<n; i++){
			int xx=cx[pts[i].st];
			for(int j=cy[pts[i].nd]; j<cy.size(); j++){
				tim[xx][j]=min(tim[xx][j], Y[j+1]-pts[i].nd);
			}
		}
		vector<pair<int, pair<int, int> > > V;
		for(int i=0; i<cx.size(); i++){
			for(int j=0; j<cy.size(); j++){
				V.pb(mp(tim[i][j], mp(i, j)));
			}
		}
		sor(V);
		//for(int x=0; x<cx.size(); x++){
			//deb(y);
			//X[cx.size()]=X[x]+h;
			for(int x=0; x<cx.size(); x++){
				M[x]=0;
			}
			for(int i=0; i<cx.size(); i++){
				for(int j=0; j<cy.size(); j++){
					len[i][j]=X[i+1]-X[i];
					if(j>=y){
						if(i+1!=cx.size()){
							M[i]=max(M[i], len[i][j]);
							//for(int x=0; x<=i; x++)M[x]=max(M[x], len[i][j]);	
						}
						else{
							//for(int x=0; x<=i; x++)M[x]=max(M[x], len[i][j]+X[x]);
						}
					}
					r[i][j]=mp(i, j);
				}
				//r[i][wsk]=mp(i, wsk);
			}
			for(int x=cx.size()-1; x>=0; x--){
				M[x]=max(M[x], M[x+1]);
			}
			for(int j=y; j<cy.size(); j++){
				for(int x=0; x<cx.size(); x++){
					M[x]=max(M[x], len[cx.size()-1][j]+X[x]);
				}
			}
			vector<int> vx;
			for(int i=0; i<cx.size(); i++){
				vx.pb(i);
			}
			for(int i=V.size()-1; i>=0; i--){
				if(i+1==V.size() || V[i].st!=V[i+1].st){
					uint a=max(Y[y], V[i].st-1);
					for(int x:vx){
						if(ans>a+max(M[x]-1, X[x]))ans=a+max(M[x]-1, X[x]);
					}
				}
				Union(V[i].nd.st, V[i].nd.nd);
				int xx=r[V[i].nd.st][V[i].nd.nd].st;
				if(V[i].nd.nd>=y){
					uint a=len[r[V[i].nd.st][V[i].nd.nd].st][r[V[i].nd.st][V[i].nd.nd].nd];
					if(xx<cx.size()-1){
						for(int x:vx){
							if(x>xx)break;
							if(a>M[x])M[x]=a;
						}
					}
					else{
						for(int x:vx){
							if(x>xx)break;
							M[x]=max(M[x], min(X[x]+a, (uint)2*INF));
						}	
					}
				//if(M[0]>=2*INF)break;
				if(i%30==0){
					for(int x=0; x<vx.size(); x++){
						while(x<vx.size() && M[vx[x]]>=2*INF){
							swap(vx[x], vx.back());
							vx.pp();
						}
					}
					sor(vx);
				}
			}
			//deb(x, y, ans);
			//if(M<INF)ans=min(ans, max(X[x], M)+Y[y]);
		}
	}
	cout<<ans;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(int i=0; i<pts.size(); i++){
      |               ~^~~~~~~~~~~
cultivation.cpp:85:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  for(int y=0; y<cy.size(); y++){
      |               ~^~~~~~~~~~
cultivation.cpp:86:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   for(int i=0; i<cx.size(); i++){
      |                ~^~~~~~~~~~
cultivation.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for(int j=0; j<cy.size(); j++){
      |                 ~^~~~~~~~~~
cultivation.cpp:96:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |    for(int j=cy[pts[i].nd]; j<cy.size(); j++){
      |                             ~^~~~~~~~~~
cultivation.cpp:101:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |   for(int i=0; i<cx.size(); i++){
      |                ~^~~~~~~~~~
cultivation.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |    for(int j=0; j<cy.size(); j++){
      |                 ~^~~~~~~~~~
cultivation.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |    for(int x=0; x<cx.size(); x++){
      |                 ~^~~~~~~~~~
cultivation.cpp:113:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |    for(int i=0; i<cx.size(); i++){
      |                 ~^~~~~~~~~~
cultivation.cpp:114:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for(int j=0; j<cy.size(); j++){
      |                  ~^~~~~~~~~~
cultivation.cpp:117:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |       if(i+1!=cx.size()){
      |          ~~~^~~~~~~~~~~
cultivation.cpp:132:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |    for(int j=y; j<cy.size(); j++){
      |                 ~^~~~~~~~~~
cultivation.cpp:133:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for(int x=0; x<cx.size(); x++){
      |                  ~^~~~~~~~~~
cultivation.cpp:138:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |    for(int i=0; i<cx.size(); i++){
      |                 ~^~~~~~~~~~
cultivation.cpp:142:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     if(i+1==V.size() || V[i].st!=V[i+1].st){
      |        ~~~^~~~~~~~~~
cultivation.cpp:152:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |      if(xx<cx.size()-1){
      |         ~~^~~~~~~~~~~~
cultivation.cpp:166:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  166 |      for(int x=0; x<vx.size(); x++){
      |                   ~^~~~~~~~~~
cultivation.cpp:167:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |       while(x<vx.size() && M[vx[x]]>=2*INF){
      |             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 284 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 284 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 6 ms 552 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 9 ms 460 KB Output is correct
25 Correct 7 ms 412 KB Output is correct
26 Correct 8 ms 460 KB Output is correct
27 Correct 8 ms 460 KB Output is correct
28 Correct 8 ms 460 KB Output is correct
29 Correct 7 ms 424 KB Output is correct
30 Correct 12 ms 440 KB Output is correct
31 Correct 8 ms 460 KB Output is correct
32 Correct 9 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 284 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 6 ms 552 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 9 ms 460 KB Output is correct
25 Correct 7 ms 412 KB Output is correct
26 Correct 8 ms 460 KB Output is correct
27 Correct 8 ms 460 KB Output is correct
28 Correct 8 ms 460 KB Output is correct
29 Correct 7 ms 424 KB Output is correct
30 Correct 12 ms 440 KB Output is correct
31 Correct 8 ms 460 KB Output is correct
32 Correct 9 ms 460 KB Output is correct
33 Correct 31 ms 332 KB Output is correct
34 Correct 421 ms 1080 KB Output is correct
35 Correct 264 ms 828 KB Output is correct
36 Correct 402 ms 868 KB Output is correct
37 Correct 339 ms 824 KB Output is correct
38 Correct 425 ms 876 KB Output is correct
39 Correct 421 ms 860 KB Output is correct
40 Correct 409 ms 1164 KB Output is correct
41 Correct 157 ms 624 KB Output is correct
42 Correct 187 ms 652 KB Output is correct
43 Correct 414 ms 1032 KB Output is correct
44 Correct 145 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 108 ms 1096 KB Output is correct
22 Correct 149 ms 1184 KB Output is correct
23 Correct 122 ms 1116 KB Output is correct
24 Correct 101 ms 1208 KB Output is correct
25 Correct 130 ms 1100 KB Output is correct
26 Correct 30 ms 724 KB Output is correct
27 Correct 159 ms 1132 KB Output is correct
28 Correct 125 ms 1104 KB Output is correct
29 Correct 133 ms 1116 KB Output is correct
30 Correct 158 ms 1096 KB Output is correct
31 Correct 136 ms 1096 KB Output is correct
32 Correct 130 ms 1092 KB Output is correct
33 Correct 158 ms 1152 KB Output is correct
34 Correct 98 ms 1168 KB Output is correct
35 Correct 107 ms 1100 KB Output is correct
36 Correct 124 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 284 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 6 ms 552 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 9 ms 460 KB Output is correct
25 Correct 7 ms 412 KB Output is correct
26 Correct 8 ms 460 KB Output is correct
27 Correct 8 ms 460 KB Output is correct
28 Correct 8 ms 460 KB Output is correct
29 Correct 7 ms 424 KB Output is correct
30 Correct 12 ms 440 KB Output is correct
31 Correct 8 ms 460 KB Output is correct
32 Correct 9 ms 460 KB Output is correct
33 Correct 31 ms 332 KB Output is correct
34 Correct 421 ms 1080 KB Output is correct
35 Correct 264 ms 828 KB Output is correct
36 Correct 402 ms 868 KB Output is correct
37 Correct 339 ms 824 KB Output is correct
38 Correct 425 ms 876 KB Output is correct
39 Correct 421 ms 860 KB Output is correct
40 Correct 409 ms 1164 KB Output is correct
41 Correct 157 ms 624 KB Output is correct
42 Correct 187 ms 652 KB Output is correct
43 Correct 414 ms 1032 KB Output is correct
44 Correct 145 ms 688 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 2 ms 560 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 412 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 2 ms 460 KB Output is correct
53 Correct 1 ms 308 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 2 ms 460 KB Output is correct
56 Correct 2 ms 460 KB Output is correct
57 Correct 1 ms 296 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 2 ms 332 KB Output is correct
60 Correct 2 ms 460 KB Output is correct
61 Correct 2 ms 460 KB Output is correct
62 Correct 2 ms 332 KB Output is correct
63 Correct 4 ms 460 KB Output is correct
64 Correct 2 ms 464 KB Output is correct
65 Correct 108 ms 1096 KB Output is correct
66 Correct 149 ms 1184 KB Output is correct
67 Correct 122 ms 1116 KB Output is correct
68 Correct 101 ms 1208 KB Output is correct
69 Correct 130 ms 1100 KB Output is correct
70 Correct 30 ms 724 KB Output is correct
71 Correct 159 ms 1132 KB Output is correct
72 Correct 125 ms 1104 KB Output is correct
73 Correct 133 ms 1116 KB Output is correct
74 Correct 158 ms 1096 KB Output is correct
75 Correct 136 ms 1096 KB Output is correct
76 Correct 130 ms 1092 KB Output is correct
77 Correct 158 ms 1152 KB Output is correct
78 Correct 98 ms 1168 KB Output is correct
79 Correct 107 ms 1100 KB Output is correct
80 Correct 124 ms 1124 KB Output is correct
81 Correct 1880 ms 2732 KB Output is correct
82 Correct 1907 ms 2808 KB Output is correct
83 Execution timed out 2063 ms 3192 KB Time limit exceeded
84 Halted 0 ms 0 KB -