Submission #1115306

# Submission time Handle Problem Language Result Execution time Memory
1115306 2024-11-20T10:18:44 Z modwwe Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
30 / 100
5000 ms 59312 KB
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int  long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}
void phongbeo();
const int inf = 1e16;
const ll mod2 = 1e9 + 7;
const int  mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0)x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};
ll n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r,p ;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo();
    // checktime
}
vector<int> a;
vector<int> d;
vector<int> b;
vector<int> c;
vector<int> sor;
int  ac_lef[300001];
int ac_right[300001];
int nearest[600001];
int pre[600001];
int hihi[600001];
int suf[300001];
void inside(vector<int> a,vector<int> b,int x,int y)
{
    for(int i=0; i<n; i++)
    {
        ac_lef[i]=n-(upper_bound(b.begin(),b.end(),a[i]+x)-b.begin());/// can co it nhat bao nhieu con lon hon
        ac_right[i]=n-(lower_bound(b.begin(),b.end(),a[i]-x)-b.begin())-1;
        /// ac_left<=x<=ac_right
    }
    for(int i=0; i<n; i++)
    {
        if(y==0)
        {
            if(nearest[i]-i<ac_lef[i])suf[i]++;
            if(n-i-1<ac_lef[i])///it nhat can ac_left canh lon hon => ac_left+i-1 ko dc do xuong
            {
                suf[min(ac_lef[i]+i-1,i+n-1)-n+1]++;
            }
            if(nearest[i]>i+ac_right[i])
            {
                pre[max(i+ac_right[i]+1,n-1)-n+1]++;
                pre[i+1]--;
            }
        }
        else if(i!=n-1)
        {
            if(i+n-nearest[i+n]<ac_lef[i])pre[i+1]++;
            if(i<ac_lef[i])
            {
                pre[max(i+n-ac_lef[i]+1,i+1)]++;
            }
            if(nearest[i+n]<i+n-ac_right[i])
            {
                suf[min(i+n-ac_right[i]-1,n-1)]++;
                suf[i]--;
            }
        }
    }
}
void outside(vector<int> a,vector<int> b,int x,int y)
{
    for(int i=0; i<n; i++)
    {
        ac_lef[i]=n-(upper_bound(b.begin(),b.end(),a[i]+x)-b.begin());/// can co it nhat bao nhieu con lon hon
        ac_right[i]=n-(lower_bound(b.begin(),b.end(),a[i]-x)-b.begin())-1;
        /// ac_left<=x<=ac_right
    }
    for(int i=0; i<n; i++)
    {
        if(y==0)
        {
            if(i==n-1) continue;
            int least=hihi[i]-(i+n);
            if(least<ac_lef[i])
            {
                pre[i+1]++;
                pre[i+ac_lef[i]+1]--;
            }
            if(least>ac_right[i])
                pre[i+1]++;
            else
                pre[i+ac_right[i]+2]++;
        }
        else
        {
            if(i==0) continue;
            int least=(i)-hihi[i+n];
            if(least<ac_lef[i])
            {
                suf[i]++;
                if(i-ac_lef[i]>=0)
                    suf[i-ac_lef[i]]--;
            }
            if(least>ac_right[i])
                suf[i]++;
            else if(i-ac_right[i]-1>=0)
                suf[i-ac_right[i]-1]++;
        }
    }
}
bool get()
{
    for(int i=1; i<=n; i++)
        pre[i]+=pre[i-1];
    for(int i=n-1; i>=0; --i)
        suf[i]+=suf[i+1];
    for(int i=1; i<n; i++)
        if(!pre[i]&&!suf[i])
        {
            return 1;
        }
    return 0;
}
bool solve(vector<int> b,vector<int> c,int x)
{
  for(int i=0; i<=n; i++)
        pre[i]=suf[i]=0;    /// find l and r of i
    inside(a,b,x,0);
    outside(a,c,x,0);
    inside(d,b,x,n);
    outside(d,c,x,n);
    if(get())return 1;
    for(int i=0; i<n; i++)
    {
        if(abs(a[i]-b[i])>x) return 0;
    }
    for(int i=n-1; i>=0; --i)
    {
        if(abs(d[i]-c[n-1-i])>x) return 0;
    }
    return 1;
///    for(int i=1; i<=n; i++)
}
bool check(int x)
{
    return (solve(b,c,x)|solve(c,b,x));
}
void phongbeo()
{
    cin>>n;
    a.resize(n);
    d.resize(n);
    b.resize(n);
    c.resize(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>d[i];
    l=0;
    for(int i=n-1; i>=0; i--)
    {
        while(l<n&&d[l]>=a[i])l++;
        hihi[i]=l+n-1;
        //cout<<hihi[i]<<" "<<i,down
        nearest[i]=min(l+n-1,i+n-1);
     ///    cout<<l<<" "<<i<<" "<<nearest[i]<<" "<<i+n-1,down
    }
    l=n-1;
    for(int i=0; i<n; i++)
    {
        while(l>=0&&a[l]>d[i]) l--;
        hihi[i+n]=l+1;
        nearest[i+n]=max(l+1,i+1);
    }
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
        cin>>c[i];
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    l=0;
    r=1e9;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(check(mid))r=mid-1;
        else l=mid+1;
    }
    cout<<r+1;
}

Compilation message

Main.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main()
      | ^~~~
Main.cpp: In function 'void phongbeo()':
Main.cpp:252:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  252 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In function 'int main()':
Main.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:79:9: note: in expansion of macro 'fin'
   79 |         fin(task);
      |         ^~~
Main.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:80:9: note: in expansion of macro 'fou'
   80 |         fou(task);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10744 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10744 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 2 ms 10576 KB Output is correct
20 Correct 2 ms 10576 KB Output is correct
21 Correct 3 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10760 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 2 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10744 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 2 ms 10576 KB Output is correct
20 Correct 2 ms 10576 KB Output is correct
21 Correct 3 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10760 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 2 ms 10576 KB Output is correct
26 Correct 14 ms 10832 KB Output is correct
27 Correct 21 ms 10832 KB Output is correct
28 Correct 12 ms 10832 KB Output is correct
29 Correct 2 ms 10576 KB Output is correct
30 Correct 28 ms 10908 KB Output is correct
31 Correct 21 ms 10900 KB Output is correct
32 Correct 9 ms 10576 KB Output is correct
33 Correct 5 ms 10576 KB Output is correct
34 Correct 11 ms 10832 KB Output is correct
35 Correct 11 ms 10904 KB Output is correct
36 Correct 34 ms 10844 KB Output is correct
37 Correct 12 ms 10832 KB Output is correct
38 Correct 13 ms 10908 KB Output is correct
39 Correct 12 ms 10832 KB Output is correct
40 Correct 19 ms 10832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4501 ms 45124 KB Output is correct
2 Correct 4328 ms 53192 KB Output is correct
3 Correct 3644 ms 47488 KB Output is correct
4 Correct 4564 ms 56856 KB Output is correct
5 Correct 4349 ms 53168 KB Output is correct
6 Correct 109 ms 11844 KB Output is correct
7 Correct 3281 ms 59312 KB Output is correct
8 Correct 3220 ms 54084 KB Output is correct
9 Correct 4716 ms 58720 KB Output is correct
10 Correct 4591 ms 56752 KB Output is correct
11 Execution timed out 5051 ms 56696 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10744 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 2 ms 10576 KB Output is correct
20 Correct 2 ms 10576 KB Output is correct
21 Correct 3 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10760 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 2 ms 10576 KB Output is correct
26 Correct 14 ms 10832 KB Output is correct
27 Correct 21 ms 10832 KB Output is correct
28 Correct 12 ms 10832 KB Output is correct
29 Correct 2 ms 10576 KB Output is correct
30 Correct 28 ms 10908 KB Output is correct
31 Correct 21 ms 10900 KB Output is correct
32 Correct 9 ms 10576 KB Output is correct
33 Correct 5 ms 10576 KB Output is correct
34 Correct 11 ms 10832 KB Output is correct
35 Correct 11 ms 10904 KB Output is correct
36 Correct 34 ms 10844 KB Output is correct
37 Correct 12 ms 10832 KB Output is correct
38 Correct 13 ms 10908 KB Output is correct
39 Correct 12 ms 10832 KB Output is correct
40 Correct 19 ms 10832 KB Output is correct
41 Correct 4501 ms 45124 KB Output is correct
42 Correct 4328 ms 53192 KB Output is correct
43 Correct 3644 ms 47488 KB Output is correct
44 Correct 4564 ms 56856 KB Output is correct
45 Correct 4349 ms 53168 KB Output is correct
46 Correct 109 ms 11844 KB Output is correct
47 Correct 3281 ms 59312 KB Output is correct
48 Correct 3220 ms 54084 KB Output is correct
49 Correct 4716 ms 58720 KB Output is correct
50 Correct 4591 ms 56752 KB Output is correct
51 Execution timed out 5051 ms 56696 KB Time limit exceeded
52 Halted 0 ms 0 KB -