답안 #999449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999449 2024-06-15T13:54:58 Z AdamGS Cultivation (JOI17_cultivation) C++17
55 / 100
2000 ms 996 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=2e9+7;
const int LIM=307;
pair<ll,ll>T[LIM];
ll R, C, n;
vector<pair<ll,ll>>Ci, Di, Ei;
ll solveab(ll a, ll b) {
  ll c=0, d=0, cpd=0, lst=1;
  ll po=0, ko=Ci.size()-1;
  while(po<ko) {
    ll sr=(po+ko)/2;
    if(Ci[sr].st>b) po=sr+1; else ko=sr;
  }
  c=Ci[po].nd;
  po=0; ko=Di.size()-1;
  while(po<ko) {
    ll sr=(po+ko)/2;
    if(Di[sr].st>b) po=sr+1; else ko=sr;
  }
  d=Di[po].nd;
  po=0; ko=(int)Ei.size()-1;
  while(po<ko) {
    ll sr=(po+ko)/2;
    if(Ei[sr].st<b) po=sr+1; else ko=sr;
  }
  if(Ei.size()>0 && Ei[po].st>=b) cpd=max(Ei[po].nd, 0ll);
  return a+b+max(c+d, cpd);
}
ll solvea(ll a) {
  Ci.clear(); Di.clear(); Ei.clear();
  vector<pair<ll,ll>>P;
  rep(i, n) P.pb({T[i].nd, i});
  sort(all(P));
  rep(i, n) {
    vector<pair<ll,ll>>Q;
    rep(j, i+1) Q.pb({max(1ll, T[P[j].nd].st-a), T[P[j].nd].st});
    sort(all(Q));
    ll ma=1, mi=0;
    for(auto j : Q) {
      mi=max(mi, j.st-ma-1);
      ma=max(ma, j.nd);
    }
    mi=max(mi, R-ma);
    if(Q[0].st!=1) mi=INF;
    Ci.pb({mi, P[i].st-1});
  }
  rep(i, n) {
    vector<pair<ll,ll>>Q;
    rep(j, i+1) Q.pb({max(1ll, T[P[n-j-1].nd].st-a), T[P[n-j-1].nd].st});
    sort(all(Q));
    ll ma=1, mi=0;
    for(auto j : Q) {
      mi=max(mi, j.st-ma-1);
      ma=max(ma, j.nd);
    }
    mi=max(mi, R-ma);
    if(Q[0].st!=1) mi=INF;
    Di.pb({mi, C-P[n-i-1].st});
  }
  rep(xd, 2) {
    rep(j, n) rep(i, j) {
      if(T[P[i].nd].st<=T[P[j].nd].st) {
        ll mi=R+1, ma=0;
        bool czy=false;
        for(int l=i+1; l<j; ++l) {
          if(T[P[l].nd].st>=T[P[j].nd].st) mi=min(mi, T[P[l].nd].st-a);
          if(T[P[l].nd].st<=T[P[i].nd].st) ma=max(ma, T[P[l].nd].st);
          if(T[P[l].nd].st>=T[P[i].nd].st && T[P[l].nd].st<=T[P[j].nd].st) czy=true;
        }
        if(czy || mi<=0) Ei.pb({-1, abs(P[i].st-P[j].st)-1});
        else if(mi==10*INF || ma==0) Ei.pb({10*INF, abs(P[i].st-P[j].st)-1});
        else Ei.pb({mi-ma-2, abs(P[i].st-P[j].st)-1});
      }
    }
    reverse(all(P));
  }
  sort(all(Ei));
  for(int i=(int)Ei.size()-2; i>=0; --i) Ei[i].nd=max(Ei[i].nd, Ei[i+1].nd);
  vector<ll>A;
  rep(i, n) A.pb(T[i].st);
  sort(all(A));
  ll b=R-A[n-1], apb=0;
  rep(i, n-1) apb=max(apb, A[i+1]-A[i]-1);
  ll ans=INF;
  rep(i, n) {
    ll x=R-T[i].st;
    if(x>=b && a+x>=apb) ans=min(ans, solveab(a, x));
  }
  rep(i, n) rep(j, i) {
    ll x=abs(T[i].st-T[j].st)-1;
    if(x==-1 || x<apb) continue;
    ll y=x-a;
    if(y>=b) ans=min(ans, solveab(a, y));
  }
  return ans;
}
ll solve() {
  ll ans=INF;
  rep(i, n) ans=min(ans, solvea(T[i].st-1));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> R >> C >> n;
  rep(i, n) cin >> T[i].st >> T[i].nd;
  ll ans=INF;
  rep(i, 4) {
    ans=min(ans, solve());
    rep(j, n) T[j]={C-T[j].nd+1, T[j].st};
    swap(R, C);
  }
  cout << ans << '\n';
}

Compilation message

cultivation.cpp: In function 'll solveab(ll, ll)':
cultivation.cpp:16:23: warning: unused variable 'lst' [-Wunused-variable]
   16 |   ll c=0, d=0, cpd=0, lst=1;
      |                       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 118 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 37 ms 344 KB Output is correct
22 Correct 858 ms 700 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Execution timed out 2021 ms 996 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 118 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 37 ms 344 KB Output is correct
22 Correct 858 ms 700 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Execution timed out 2021 ms 996 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 4 ms 480 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 4 ms 472 KB Output is correct
18 Correct 4 ms 344 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 4 ms 480 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 4 ms 472 KB Output is correct
18 Correct 4 ms 344 KB Output is correct
19 Correct 4 ms 476 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 523 ms 604 KB Output is correct
22 Correct 506 ms 652 KB Output is correct
23 Correct 480 ms 848 KB Output is correct
24 Correct 449 ms 660 KB Output is correct
25 Correct 507 ms 856 KB Output is correct
26 Correct 454 ms 600 KB Output is correct
27 Correct 377 ms 648 KB Output is correct
28 Correct 501 ms 600 KB Output is correct
29 Correct 498 ms 652 KB Output is correct
30 Correct 528 ms 604 KB Output is correct
31 Correct 513 ms 600 KB Output is correct
32 Correct 495 ms 648 KB Output is correct
33 Correct 291 ms 648 KB Output is correct
34 Correct 449 ms 600 KB Output is correct
35 Correct 385 ms 648 KB Output is correct
36 Correct 458 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 118 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 37 ms 344 KB Output is correct
22 Correct 858 ms 700 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Execution timed out 2021 ms 996 KB Time limit exceeded
25 Halted 0 ms 0 KB -