Submission #955074

# Submission time Handle Problem Language Result Execution time Memory
955074 2024-03-29T10:29:43 Z edogawa_something Cultivation (JOI17_cultivation) C++17
5 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(),v.end()
#define pow poww
const ll M=5e5+10;
const ll inf=2e18;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  ll res=1;
  x%=mod; 
  while(y>0){
    if((y&1))
    res*=x,res%=mod;
    x*=x,x%=mod;
    y=(y>>1);
  }
  return res;
}
ll r,c,n;
pii a[M];
vii v,vv;
bool chk(ll x,ll y){
  if(v.empty())
  return 0;
  sort(all(v));
  if(v[0]-1>x||r-v.back()>y)
  return 0;
  for(int i=1;i<v.size();i++){
    if(v[i]-v[i-1]-1>x+y)
    return 0;
  }
  return 1;
}
ll solve(ll x,ll y){
  v.clear(),vv.clear();
  for(int i=0;i<n;i++){
    if(i==0)
    v.pb(a[i].F);
    if(i>0){
    if(a[i].S==a[i-1].S){
      v.pb(a[i].F);
    }
    else{
      if(chk(x,y))
      vv.pb(a[i-1].S);
      v.clear();
      v.pb(a[i].F);
    }
    }
  }
  if(chk(x,y))
  vv.pb(a[n-1].S);
  if(vv.empty())
  return inf;
  ll res=0;
  sort(all(vv));
  res=vv[0]-1+c-vv.back();
  for(int i=1;i<vv.size();i++){
    res=max(res,vv[i]-vv[i-1]-1);
  }
  return res;
}
int main(){
  ios_base::sync_with_stdio(0),cin.tie(0);
  int TC=1;
  //cin>>TC;
  while(TC--){
    cin>>r>>c>>n;
    for(int i=0;i<n;i++){
      cin>>a[i].S>>a[i].F;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    swap(a[i].F,a[i].S);
    ll ans=inf;
    for(ll i=0;i<=50;i++){
      for(ll j=0;j<=50;j++){
        ans=min(ans,solve(i,j)+i+j);
      }
    }
    cout<<ans<<'\n';
  }
  return 0;
}
/*

*/  

Compilation message

cultivation.cpp: In function 'bool chk(ll, ll)':
cultivation.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i=1;i<v.size();i++){
      |               ~^~~~~~~~~
cultivation.cpp: In function 'll solve(ll, ll)':
cultivation.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=1;i<vv.size();i++){
      |               ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -