# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27828 | 2017-07-14T07:31:20 Z | suhgyuho_william | Cultivation (JOI17_cultivation) | C++14 | 2000 ms | 3652 KB |
#include <bits/stdc++.h> #define lld long long #define pii pair<int,int> #define pll pair<lld,lld> #define pb push_back #define next nextt #define left leftt #define right rightt #define Inf 1000000000 #define Linf 1000000000000000000LL #define Mod 1000000007LL using namespace std; int N; lld R,C,ans; struct data{ lld x,y; }a[302]; multiset<lld> S; void process(lld l,lld r){ lld ly,ry,lry; ly = ry = lry = 0; vector<pll> tmp; for(int i=1; i<=N; i++){ tmp.pb({max((lld)1,a[i].x-l),a[i].y}); tmp.pb({min(R,a[i].x+r)+1,-a[i].y}); } sort(tmp.begin(),tmp.end()); if(tmp[0].first != 1 || tmp.back().first != R+1) return; for(int i=0; i<tmp.size(); i++){ int e; for(int j=i; j<tmp.size(); j++){ if(tmp[i].first != tmp[j].first) break; e = j; } for(int j=i; j<=e; j++){ if(tmp[j].second > 0) S.insert(tmp[j].second); else S.erase(S.find(-tmp[j].second)); } if(S.empty() && tmp[i].first <= R) return; if(S.empty()) break; auto it = S.end(); it--; ly = max(ly,*S.begin()-1); ry = max(ry,C-(*it)); lld bef; for(it = S.begin(); it != S.end(); it++){ if(it == S.begin()){ bef = *it; continue; } lry = max(lry,*it-bef-1); bef = *it; } i = e; } if(ly > ry) swap(ly,ry); if(ly+ry < lry){ ry = lry-ly; } ans = min(ans,l+r+ly+ry); } int main(){ //freopen("input.txt","r",stdin); scanf("%lld %lld %d",&R,&C,&N); for(int i=1; i<=N; i++){ scanf("%d %d",&a[i].x,&a[i].y); } sort(a+1,a+N+1,[&](data &x,data &y){ return x.x < y.x; }); ans = Linf; vector<int> X; a[N+1].x = R+1; for(int i=0; i<=N; i++){ for(int j=i; j<=N+1; j++){ X.pb(a[j].x-a[i].x); X.pb(a[j].x-a[i].x+1); X.pb(max((lld)0,a[j].x-a[i].x-1)); } } sort(X.begin(),X.end()); X.erase(unique(X.begin(),X.end()),X.end()); for(auto &i : X){ for(auto &j : X){ process(i,j); } } process(3,0); printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Correct | 0 ms | 2032 KB | Output is correct |
3 | Correct | 0 ms | 2032 KB | Output is correct |
4 | Correct | 0 ms | 2032 KB | Output is correct |
5 | Correct | 0 ms | 2032 KB | Output is correct |
6 | Correct | 0 ms | 2032 KB | Output is correct |
7 | Correct | 0 ms | 2032 KB | Output is correct |
8 | Correct | 0 ms | 2032 KB | Output is correct |
9 | Correct | 0 ms | 2032 KB | Output is correct |
10 | Correct | 0 ms | 2032 KB | Output is correct |
11 | Correct | 0 ms | 2032 KB | Output is correct |
12 | Correct | 0 ms | 2032 KB | Output is correct |
13 | Correct | 0 ms | 2032 KB | Output is correct |
14 | Correct | 0 ms | 2032 KB | Output is correct |
15 | Correct | 0 ms | 2032 KB | Output is correct |
16 | Correct | 0 ms | 2032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Correct | 0 ms | 2032 KB | Output is correct |
3 | Correct | 0 ms | 2032 KB | Output is correct |
4 | Correct | 0 ms | 2032 KB | Output is correct |
5 | Correct | 0 ms | 2032 KB | Output is correct |
6 | Correct | 0 ms | 2032 KB | Output is correct |
7 | Correct | 0 ms | 2032 KB | Output is correct |
8 | Correct | 0 ms | 2032 KB | Output is correct |
9 | Correct | 0 ms | 2032 KB | Output is correct |
10 | Correct | 0 ms | 2032 KB | Output is correct |
11 | Correct | 0 ms | 2032 KB | Output is correct |
12 | Correct | 0 ms | 2032 KB | Output is correct |
13 | Correct | 0 ms | 2032 KB | Output is correct |
14 | Correct | 0 ms | 2032 KB | Output is correct |
15 | Correct | 0 ms | 2032 KB | Output is correct |
16 | Correct | 0 ms | 2032 KB | Output is correct |
17 | Correct | 3 ms | 2032 KB | Output is correct |
18 | Correct | 23 ms | 2172 KB | Output is correct |
19 | Correct | 9 ms | 2032 KB | Output is correct |
20 | Correct | 0 ms | 2032 KB | Output is correct |
21 | Correct | 33 ms | 2172 KB | Output is correct |
22 | Correct | 93 ms | 2304 KB | Output is correct |
23 | Correct | 3 ms | 2032 KB | Output is correct |
24 | Correct | 196 ms | 2500 KB | Output is correct |
25 | Correct | 113 ms | 2500 KB | Output is correct |
26 | Correct | 263 ms | 3652 KB | Output is correct |
27 | Correct | 276 ms | 3652 KB | Output is correct |
28 | Correct | 156 ms | 2500 KB | Output is correct |
29 | Correct | 239 ms | 3652 KB | Output is correct |
30 | Correct | 259 ms | 3652 KB | Output is correct |
31 | Correct | 256 ms | 3652 KB | Output is correct |
32 | Correct | 266 ms | 3652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Correct | 0 ms | 2032 KB | Output is correct |
3 | Correct | 0 ms | 2032 KB | Output is correct |
4 | Correct | 0 ms | 2032 KB | Output is correct |
5 | Correct | 0 ms | 2032 KB | Output is correct |
6 | Correct | 0 ms | 2032 KB | Output is correct |
7 | Correct | 0 ms | 2032 KB | Output is correct |
8 | Correct | 0 ms | 2032 KB | Output is correct |
9 | Correct | 0 ms | 2032 KB | Output is correct |
10 | Correct | 0 ms | 2032 KB | Output is correct |
11 | Correct | 0 ms | 2032 KB | Output is correct |
12 | Correct | 0 ms | 2032 KB | Output is correct |
13 | Correct | 0 ms | 2032 KB | Output is correct |
14 | Correct | 0 ms | 2032 KB | Output is correct |
15 | Correct | 0 ms | 2032 KB | Output is correct |
16 | Correct | 0 ms | 2032 KB | Output is correct |
17 | Correct | 3 ms | 2032 KB | Output is correct |
18 | Correct | 23 ms | 2172 KB | Output is correct |
19 | Correct | 9 ms | 2032 KB | Output is correct |
20 | Correct | 0 ms | 2032 KB | Output is correct |
21 | Correct | 33 ms | 2172 KB | Output is correct |
22 | Correct | 93 ms | 2304 KB | Output is correct |
23 | Correct | 3 ms | 2032 KB | Output is correct |
24 | Correct | 196 ms | 2500 KB | Output is correct |
25 | Correct | 113 ms | 2500 KB | Output is correct |
26 | Correct | 263 ms | 3652 KB | Output is correct |
27 | Correct | 276 ms | 3652 KB | Output is correct |
28 | Correct | 156 ms | 2500 KB | Output is correct |
29 | Correct | 239 ms | 3652 KB | Output is correct |
30 | Correct | 259 ms | 3652 KB | Output is correct |
31 | Correct | 256 ms | 3652 KB | Output is correct |
32 | Correct | 266 ms | 3652 KB | Output is correct |
33 | Correct | 6 ms | 3652 KB | Output is correct |
34 | Correct | 203 ms | 3652 KB | Output is correct |
35 | Correct | 266 ms | 3652 KB | Output is correct |
36 | Correct | 263 ms | 3652 KB | Output is correct |
37 | Correct | 199 ms | 3652 KB | Output is correct |
38 | Correct | 316 ms | 3652 KB | Output is correct |
39 | Correct | 296 ms | 3652 KB | Output is correct |
40 | Correct | 289 ms | 3652 KB | Output is correct |
41 | Correct | 216 ms | 3652 KB | Output is correct |
42 | Correct | 226 ms | 3652 KB | Output is correct |
43 | Correct | 253 ms | 3652 KB | Output is correct |
44 | Correct | 276 ms | 3652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 863 ms | 2032 KB | Output is correct |
2 | Execution timed out | 2000 ms | 2032 KB | Execution timed out |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 863 ms | 2032 KB | Output is correct |
2 | Execution timed out | 2000 ms | 2032 KB | Execution timed out |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Correct | 0 ms | 2032 KB | Output is correct |
3 | Correct | 0 ms | 2032 KB | Output is correct |
4 | Correct | 0 ms | 2032 KB | Output is correct |
5 | Correct | 0 ms | 2032 KB | Output is correct |
6 | Correct | 0 ms | 2032 KB | Output is correct |
7 | Correct | 0 ms | 2032 KB | Output is correct |
8 | Correct | 0 ms | 2032 KB | Output is correct |
9 | Correct | 0 ms | 2032 KB | Output is correct |
10 | Correct | 0 ms | 2032 KB | Output is correct |
11 | Correct | 0 ms | 2032 KB | Output is correct |
12 | Correct | 0 ms | 2032 KB | Output is correct |
13 | Correct | 0 ms | 2032 KB | Output is correct |
14 | Correct | 0 ms | 2032 KB | Output is correct |
15 | Correct | 0 ms | 2032 KB | Output is correct |
16 | Correct | 0 ms | 2032 KB | Output is correct |
17 | Correct | 3 ms | 2032 KB | Output is correct |
18 | Correct | 23 ms | 2172 KB | Output is correct |
19 | Correct | 9 ms | 2032 KB | Output is correct |
20 | Correct | 0 ms | 2032 KB | Output is correct |
21 | Correct | 33 ms | 2172 KB | Output is correct |
22 | Correct | 93 ms | 2304 KB | Output is correct |
23 | Correct | 3 ms | 2032 KB | Output is correct |
24 | Correct | 196 ms | 2500 KB | Output is correct |
25 | Correct | 113 ms | 2500 KB | Output is correct |
26 | Correct | 263 ms | 3652 KB | Output is correct |
27 | Correct | 276 ms | 3652 KB | Output is correct |
28 | Correct | 156 ms | 2500 KB | Output is correct |
29 | Correct | 239 ms | 3652 KB | Output is correct |
30 | Correct | 259 ms | 3652 KB | Output is correct |
31 | Correct | 256 ms | 3652 KB | Output is correct |
32 | Correct | 266 ms | 3652 KB | Output is correct |
33 | Correct | 6 ms | 3652 KB | Output is correct |
34 | Correct | 203 ms | 3652 KB | Output is correct |
35 | Correct | 266 ms | 3652 KB | Output is correct |
36 | Correct | 263 ms | 3652 KB | Output is correct |
37 | Correct | 199 ms | 3652 KB | Output is correct |
38 | Correct | 316 ms | 3652 KB | Output is correct |
39 | Correct | 296 ms | 3652 KB | Output is correct |
40 | Correct | 289 ms | 3652 KB | Output is correct |
41 | Correct | 216 ms | 3652 KB | Output is correct |
42 | Correct | 226 ms | 3652 KB | Output is correct |
43 | Correct | 253 ms | 3652 KB | Output is correct |
44 | Correct | 276 ms | 3652 KB | Output is correct |
45 | Correct | 863 ms | 2032 KB | Output is correct |
46 | Execution timed out | 2000 ms | 2032 KB | Execution timed out |
47 | Halted | 0 ms | 0 KB | - |