Submission #1220517

#TimeUsernameProblemLanguageResultExecution timeMemory
1220517moha1111Rice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <cstdio>
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define all(a) a.begin() , a.end()
const long long mod = 1000000007;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_multiset;

void usaco(string s)
{
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

void solve()
{
    long long r , l , b;
    cin >> r >> l;
    int a[r];
    for(int i = 0 ; i < r ; i++)
        cin >> a[i];

    cin >> b;

    long long st = 1 , en = r , ans;
    while(st <= en)
    {
        long long mid = (st + en) / 2;
        indexed_multiset cur;
        for(int i = 0 ; i < mid ; i++)
            cur.insert(a[i]);

        if(mid % 2 == 0)
        {
            if(*cur.find_by_order(mid / 2) <= b)
            {
                st = mid + 1 , ans = mid;
                continue;
            }
            for(int i = mid ; i < r ; i++)
            {
                cur.insert(a[mid]);
                cur.erase(cur.find(a[i - mid]));
                if(*cur.find_by_order(mid / 2) <= b)
                {
                    st = mid + 1 , ans = mid;
                    continue;
                }
            }
            en = mid - 1;
        }
        else
        {
            if(*cur.find_by_order(mid / 2) + *cur.find_by_order(mid / 2 + 1)<= b * 2)
            {
                st = mid + 1 , ans = mid;
                continue;
            }
            for(int i = mid ; i < r ; i++)
            {
                cur.insert(a[mid]);
                cur.erase(cur.find(a[i - mid]));
                if(*cur.find_by_order(mid / 2) + *cur.find_by_order(mid / 2 + 1)<= b * 2)
                {
                    st = mid + 1 , ans = mid;
                    continue;
                }
            }
            en = mid - 1;
        }
    }
    cout << ans << '\n';
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //usaco("lostcow");
    int t = 1;
    //cin >> t;
    while(t--)
        solve();

}

Compilation message (stderr)

ricehub.cpp: In function 'void usaco(std::string)':
ricehub.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ricehub.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cct1AXwe.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6Adygf.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cct1AXwe.o: in function `main':
grader.cpp:(.text.startup+0xaa): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status