답안 #1115317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115317 2024-11-20T10:28:34 Z modwwe Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
0 / 100
4895 ms 22848 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;

};
int 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)
{
    if(y==0)
    {
        l=n-1;
        for(int i=0; i<n; i++)
        {
            while(l>=0&&b[l]>a[i]+x)l--;
            ac_lef[i]=n-(l+1);
        }
        l=n-1;
        for(int i=0; i<n; ++i)
        {
            while(l>=0&&b[l]>=a[i]-x)l--;
            ac_right[i]=n-l;
        }
    }
    else
    {
        for(int i=n-1; i>=0; --i)
        {
            while(l>=0&&b[l]>a[i]+x)l--;
            ac_lef[i]=n-(l+1);
        }
        for(int i=n-1; i>=0; --i)
        {
            while(l>=0&&b[l]>=a[i]-x)l--;
            ac_right[i]=n-l;
        }
    }
    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])
            {
                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++)
    {
        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;
    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;
}
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;
        nearest[i]=min(l+n-1,i+n-1);
    }
    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:38:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+16' to '2147483647' [-Woverflow]
   38 | const int inf = 1e16;
      |                 ^~~~
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:265:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  265 |         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);
      |         ^~~
# 결과 실행 시간 메모리 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 Incorrect 1 ms 10576 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 10576 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 10576 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4895 ms 22848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 10576 KB Output isn't correct
5 Halted 0 ms 0 KB -