답안 #1115309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115309 2024-11-20T10:19:27 Z modwwe Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
100 / 100
4958 ms 34996 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)
{
    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: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: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);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10716 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 3 ms 10576 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 10744 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10716 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 3 ms 10576 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 10744 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 10576 KB Output is correct
17 Correct 3 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 2 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10576 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 3 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10716 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 3 ms 10576 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 10744 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 10576 KB Output is correct
17 Correct 3 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 2 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10576 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 3 ms 10576 KB Output is correct
26 Correct 26 ms 10824 KB Output is correct
27 Correct 19 ms 10576 KB Output is correct
28 Correct 12 ms 10576 KB Output is correct
29 Correct 2 ms 10576 KB Output is correct
30 Correct 28 ms 10800 KB Output is correct
31 Correct 25 ms 10812 KB Output is correct
32 Correct 8 ms 10576 KB Output is correct
33 Correct 5 ms 10724 KB Output is correct
34 Correct 12 ms 10576 KB Output is correct
35 Correct 22 ms 10576 KB Output is correct
36 Correct 30 ms 10576 KB Output is correct
37 Correct 12 ms 10744 KB Output is correct
38 Correct 12 ms 10576 KB Output is correct
39 Correct 11 ms 10576 KB Output is correct
40 Correct 17 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4515 ms 22772 KB Output is correct
2 Correct 4314 ms 22880 KB Output is correct
3 Correct 3333 ms 20744 KB Output is correct
4 Correct 4228 ms 22776 KB Output is correct
5 Correct 3744 ms 23144 KB Output is correct
6 Correct 89 ms 11164 KB Output is correct
7 Correct 2809 ms 22800 KB Output is correct
8 Correct 2735 ms 22792 KB Output is correct
9 Correct 4283 ms 22772 KB Output is correct
10 Correct 4422 ms 22780 KB Output is correct
11 Correct 4340 ms 22772 KB Output is correct
12 Correct 4116 ms 32040 KB Output is correct
13 Correct 3963 ms 31036 KB Output is correct
14 Correct 2732 ms 34384 KB Output is correct
15 Correct 2848 ms 30952 KB Output is correct
16 Correct 2921 ms 30880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10716 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 3 ms 10576 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 10744 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 10576 KB Output is correct
17 Correct 3 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 2 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10576 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 3 ms 10576 KB Output is correct
26 Correct 26 ms 10824 KB Output is correct
27 Correct 19 ms 10576 KB Output is correct
28 Correct 12 ms 10576 KB Output is correct
29 Correct 2 ms 10576 KB Output is correct
30 Correct 28 ms 10800 KB Output is correct
31 Correct 25 ms 10812 KB Output is correct
32 Correct 8 ms 10576 KB Output is correct
33 Correct 5 ms 10724 KB Output is correct
34 Correct 12 ms 10576 KB Output is correct
35 Correct 22 ms 10576 KB Output is correct
36 Correct 30 ms 10576 KB Output is correct
37 Correct 12 ms 10744 KB Output is correct
38 Correct 12 ms 10576 KB Output is correct
39 Correct 11 ms 10576 KB Output is correct
40 Correct 17 ms 10576 KB Output is correct
41 Correct 4515 ms 22772 KB Output is correct
42 Correct 4314 ms 22880 KB Output is correct
43 Correct 3333 ms 20744 KB Output is correct
44 Correct 4228 ms 22776 KB Output is correct
45 Correct 3744 ms 23144 KB Output is correct
46 Correct 89 ms 11164 KB Output is correct
47 Correct 2809 ms 22800 KB Output is correct
48 Correct 2735 ms 22792 KB Output is correct
49 Correct 4283 ms 22772 KB Output is correct
50 Correct 4422 ms 22780 KB Output is correct
51 Correct 4340 ms 22772 KB Output is correct
52 Correct 4116 ms 32040 KB Output is correct
53 Correct 3963 ms 31036 KB Output is correct
54 Correct 2732 ms 34384 KB Output is correct
55 Correct 2848 ms 30952 KB Output is correct
56 Correct 2921 ms 30880 KB Output is correct
57 Correct 3220 ms 34208 KB Output is correct
58 Correct 3685 ms 30920 KB Output is correct
59 Correct 2273 ms 25544 KB Output is correct
60 Correct 4862 ms 34492 KB Output is correct
61 Correct 3877 ms 30976 KB Output is correct
62 Correct 2807 ms 27468 KB Output is correct
63 Correct 67 ms 11444 KB Output is correct
64 Correct 2766 ms 34996 KB Output is correct
65 Correct 2776 ms 29812 KB Output is correct
66 Correct 4958 ms 34496 KB Output is correct
67 Correct 3061 ms 34512 KB Output is correct
68 Correct 3023 ms 34632 KB Output is correct
69 Correct 1758 ms 26556 KB Output is correct
70 Correct 2854 ms 34516 KB Output is correct
71 Correct 2873 ms 34740 KB Output is correct
72 Correct 2903 ms 34496 KB Output is correct
73 Correct 2819 ms 34392 KB Output is correct
74 Correct 4523 ms 34372 KB Output is correct
75 Correct 2877 ms 26464 KB Output is correct
76 Correct 4274 ms 34360 KB Output is correct
77 Correct 4204 ms 30760 KB Output is correct