답안 #1110240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110240 2024-11-09T03:09:48 Z vjudge1 Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
9 / 100
116 ms 6728 KB
#include <bits/stdc++.h>
using namespace std;

#define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
#define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
#define nl "\n"
#define ss " "
#define pb emplace_back
#define fi first
#define se second
#define sz(s) (int)s.size()
#define ms(a,x) memset(a, x, sizeof (a))
#define re exit(0)
#define cn continue

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


const int mod=1e9+7;
//const int mod=998244353;
const int maxn=3e5+105;
const int maxm=4*maxn+5;
const ll inf=1e18;

mt19937 ran(time(0));
mt19937_64 ran64(time(0));

void rf(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen("o.inp","r")){
        freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
    }
}

void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
    if(x<0) x+=mod;
}

int n, m, a[maxm], b[maxn], c[maxn];

bool getbit(int mask, int i)
{
    return (mask>>i)&1;
}

bool check(int mask)
{
    if(__builtin_popcount(mask)!=n) return 0;
    int cur=1;
    ff(i, 1, m-1)
    {
        if(getbit(mask, i)==getbit(mask, i-1))
        {
            ++cur;
            if(cur>=n) return 1;
        }
        else
        {
            if(cur>=n) return 1;
            cur=1;
        }
    }
    return 0;
}

signed main()
{
    rf();
    cin>>n;
    m=n+n;
    ff(i, 1, m) cin>>a[i];
    ff(i, 1, n) cin>>b[i];
    ff(i, 1, n) cin>>c[i];
    sort(b+1, b+n+1);
    sort(c+1, c+n+1);
    int ans=mod;
    for(int mask=1; mask<(1<<m); ++mask)
    {
        if(!check(mask)) continue;
        vi v0, v1;
        ff(i ,0, m-1)
        {
            if(getbit(mask, i)) v0.pb(a[i+1]);
            else v1.pb(a[i+1]);
        }
        sort(v0.begin(), v0.end());
        sort(v1.begin(), v1.end());
        int res=0;
        ff(i, 1, n) res=max(res, abs(b[i]-v0[i-1]));
        ff(i, 1, n) res=max(res, abs(c[i]-v1[i-1]));
        ans=min(ans, res);
    }
    cout<<ans<<nl;
    re;
}

Compilation message

Main.cpp: In function 'void rf()':
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:41:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4652 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4652 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 16 ms 4432 KB Output is correct
14 Correct 5 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 20 ms 4432 KB Output is correct
17 Correct 16 ms 4432 KB Output is correct
18 Correct 5 ms 4432 KB Output is correct
19 Correct 2 ms 4600 KB Output is correct
20 Correct 19 ms 4576 KB Output is correct
21 Correct 16 ms 4432 KB Output is correct
22 Correct 16 ms 4432 KB Output is correct
23 Correct 16 ms 4432 KB Output is correct
24 Correct 16 ms 4600 KB Output is correct
25 Correct 5 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4652 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 16 ms 4432 KB Output is correct
14 Correct 5 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 20 ms 4432 KB Output is correct
17 Correct 16 ms 4432 KB Output is correct
18 Correct 5 ms 4432 KB Output is correct
19 Correct 2 ms 4600 KB Output is correct
20 Correct 19 ms 4576 KB Output is correct
21 Correct 16 ms 4432 KB Output is correct
22 Correct 16 ms 4432 KB Output is correct
23 Correct 16 ms 4432 KB Output is correct
24 Correct 16 ms 4600 KB Output is correct
25 Correct 5 ms 4432 KB Output is correct
26 Incorrect 2 ms 4432 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 116 ms 6728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4652 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 16 ms 4432 KB Output is correct
14 Correct 5 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 20 ms 4432 KB Output is correct
17 Correct 16 ms 4432 KB Output is correct
18 Correct 5 ms 4432 KB Output is correct
19 Correct 2 ms 4600 KB Output is correct
20 Correct 19 ms 4576 KB Output is correct
21 Correct 16 ms 4432 KB Output is correct
22 Correct 16 ms 4432 KB Output is correct
23 Correct 16 ms 4432 KB Output is correct
24 Correct 16 ms 4600 KB Output is correct
25 Correct 5 ms 4432 KB Output is correct
26 Incorrect 2 ms 4432 KB Output isn't correct
27 Halted 0 ms 0 KB -