Submission #1087639

# Submission time Handle Problem Language Result Execution time Memory
1087639 2024-09-13T03:34:50 Z hahahaha Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
30 / 100
417 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;

#define i64 long long
#define ld long double
#define bit(n,i) ((n>>i)&1)
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define __sumairu__ signed main()
#define die_hard_onimai_fan void seggs()
#define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define brute(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".ans","w",stdout);}
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ai(n) array<int,n>
#define dbg(x) {cerr<<#x<<' '<<x<<endl;}
#define dbgArr(arr,n) {cerr<<#arr;FOR(_i,1,n)cerr<<' '<<(arr)[_i];cerr<<endl;}

template <typename T,typename U>
ostream& operator<<(ostream &os,pair<T,U>p){
    return os<<"{"<<p.fi<<", "<<p.se<<"}";
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());

i64 Rand(i64 l,i64 r)
{
    i64 ans=l+1ll*rd()*rd()%(r-l+1);
    assert(l<=ans&&ans<=r);
    return ans;
}
//const i64 base=1e9+7;
//const i64 mod=(1ll<<53)+5;

#define i64 long long
#define debug 0

const int mod=1e9+7;
//const int mod=998244353;
const int inf=1e9;
///check the limits, dummy
const int N=3e5+5;

int n;
int a[N*2];
int blue[N],red[N];

namespace sub2
{
    void solve()
    {
        vector<int>b(2*n+1);
        FOR(i,1,2*n)b[i]=a[i];

        int ans=inf;
        FOR(i,1,n+1)
        {
            sort(a+i,a+i+n);

            int mx=0;
            FOR(j,i,i+n-1)
            {
                mx=max(mx,abs(a[j]-blue[j-i+1]));
                a[j]=b[j];
            }

            vector<int>v;
            v.pb(0);
            FOR(j,1,i-1)v.pb(a[j]);
            FOR(j,i+n,2*n)v.pb(a[j]);
            sort(all(v));

            FOR(j,1,n)mx=max(mx,abs(v[j]-red[j]));

            ans=min(ans,mx);
        }
        FOR(i,1,n+1)
        {
            sort(a+i,a+i+n);

            int mx=0;
            FOR(j,i,i+n-1)
            {
                mx=max(mx,abs(a[j]-red[j-i+1]));
                a[j]=b[j];
            }

            vector<int>v;
            v.pb(0);
            FOR(j,1,i-1)v.pb(a[j]);
            FOR(j,i+n,2*n)v.pb(a[j]);
            sort(all(v));

            FOR(j,1,n)mx=max(mx,abs(v[j]-blue[j]));

            ans=min(ans,mx);
        }
        cout<<ans;
        exit(0);
    }
}
namespace sub3
{
    void solve()
    {

    }
}

die_hard_onimai_fan
{
    cin>>n;
    FOR(i,1,2*n)cin>>a[i];

    FOR(i,1,n)cin>>red[i];
    FOR(i,1,n)cin>>blue[i];
    sort(red+1,red+n+1);
    sort(blue+1,blue+n+1);

    if(n<=3000)sub2::solve();
    else sub3::solve();
}

__sumairu__
{
    FAST
    file("");

    int tt=1;//cin>>tt;
    while(tt--)seggs();
    cerr<<"\nTime elapsed: "<<TIME<<" s.\n";
}
/**
2
1 2 6 3
2 5
4 3
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:132:5: note: in expansion of macro 'file'
  132 |     file("");
      |     ^~~~
Main.cpp:17:83: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:132:5: note: in expansion of macro 'file'
  132 |     file("");
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 0 ms 344 KB Output is correct
9 Correct 0 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 0 ms 344 KB Output is correct
9 Correct 0 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 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 0 ms 344 KB Output is correct
9 Correct 0 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 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 362 ms 608 KB Output is correct
27 Correct 339 ms 476 KB Output is correct
28 Correct 186 ms 344 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 369 ms 848 KB Output is correct
31 Correct 357 ms 568 KB Output is correct
32 Correct 66 ms 344 KB Output is correct
33 Correct 17 ms 344 KB Output is correct
34 Correct 392 ms 604 KB Output is correct
35 Correct 337 ms 344 KB Output is correct
36 Correct 361 ms 604 KB Output is correct
37 Correct 107 ms 604 KB Output is correct
38 Correct 149 ms 604 KB Output is correct
39 Correct 181 ms 604 KB Output is correct
40 Correct 417 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 116 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 0 ms 344 KB Output is correct
9 Correct 0 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 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 362 ms 608 KB Output is correct
27 Correct 339 ms 476 KB Output is correct
28 Correct 186 ms 344 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 369 ms 848 KB Output is correct
31 Correct 357 ms 568 KB Output is correct
32 Correct 66 ms 344 KB Output is correct
33 Correct 17 ms 344 KB Output is correct
34 Correct 392 ms 604 KB Output is correct
35 Correct 337 ms 344 KB Output is correct
36 Correct 361 ms 604 KB Output is correct
37 Correct 107 ms 604 KB Output is correct
38 Correct 149 ms 604 KB Output is correct
39 Correct 181 ms 604 KB Output is correct
40 Correct 417 ms 344 KB Output is correct
41 Incorrect 116 ms 4948 KB Output isn't correct
42 Halted 0 ms 0 KB -