Submission #302429

# Submission time Handle Problem Language Result Execution time Memory
302429 2020-09-18T16:42:17 Z UserIsUndefined Rice Hub (IOI11_ricehub) C++14
17 / 100
246 ms 1852 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;


int besthub(int R, int L, int X[], long long B)
{

    int low = 0;

    int high = R*2;


    while(low < high){
        int mid = (high+low)/2;

//        cout << mid << " " << low << " " << high << endl;


        long long sum = 0;

        long long now = mid/2;

        long long pluss = mid - mid/2 - 1;

        long long mines = mid - (pluss + 1);


//        cout << "lenth " << mid << endl;
//        cout << now << " << now " << pluss << " << pluse " << mines << " << mines " << endl;


//        for (int i = 0 ; i < mid ; i++){
//            sum+= llabs(X[now] - X[i]);
//        }


//        cout << "first sum " << sum << endl;
//        cout << "B" << B << endl;

//        if (sum <= B){
//
//            low = mid + 1;
//            continue;
//        }

        int good = false;

//        cout << "len = " << mid << endl;
//        cout << "sums are : " << endl;


        for (int i = now ; i + pluss < R ; i++){
            long long sum = 0;

//            cout << "middation " << i << endl;
//            cout << "from " << i - mines << " to " << i + pluss << endl;
            for (int j = i - mines ; j <= i + pluss ; j++){
                sum+= llabs(X[j] - X[i]);
            }

//            cout << sum << endl;



//            int bye = X[i - mines - 1];
////            cout << "bye " << bye << endl;
//            sum-= llabs(X[i-1] - bye);
////            cout << "sum without bye " << sum << endl;
//            int hello = X[i + pluss];
////            cout << "hello " << hello << endl;
//            sum+= llabs(X[i] - hello);
////            cout << "sum with hello " << sum << endl;
//
//            sum+= llabs(X[i] - X[i-1])*(mines - 1);
//
////            cout << "sum with pre" << sum << endl;
//
//            sum-= llabs(X[i] - X[i-1])*(pluss - 1);
//
////            cout << "sum without after" << sum << endl;

//            cout << "new sum " << sum << endl;

            if (sum <= B){
                low = mid + 1;
                good = true;
                break;
            }

        }

//        cout << "\n\n\n";

        if (good)continue;

        high = mid - 1;






    }

    int best = low - 1;




//    for (int i = max(low - 5, 0) ; i <= min(low + 5, R) ; i++){
//        long long sum = 0;
//
//        long long now = X[i/2];
//
//        long long pluss = i - i/2 - 1;
//
//        long long mines = i - pluss + 1;
//
//        cout << "for " << i << endl;
//
//        cout << "sums are :\n";
//
//
//        for (int j = 0 ; j < i ; j++){
//            sum+= llabs(now - X[j]);
//        }
//
//        cout << sum << endl;
//
//        if (sum <= B){
//            best = i;
//            continue;
//        }
//
//        int good = false;
//
//
//        for (int j = now + 1 ; j + pluss - 1 < R ; j++){
//            int bye = X[j - mines];
//            sum-= llabs(X[j-1] - bye);
//            int hello = X[j + pluss];
//            sum+= llabs(X[j] - hello);
//
//            sum+= llabs(X[j] - X[j-1])*mines;
//
//            sum-= llabs(X[j] - X[j-1])*(pluss - 1);
//
//             cout << sum << endl;
//
//            if (sum <= B){
//                best = i;
//                good = true;
//                break;
//            }
//
//        }
//
//        if (good)continue;
//    }



    return best;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:21:19: warning: unused variable 'sum' [-Wunused-variable]
   21 |         long long sum = 0;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 238 ms 384 KB Output is correct
2 Correct 246 ms 384 KB Output is correct
3 Correct 17 ms 768 KB Output is correct
4 Incorrect 19 ms 1852 KB Output isn't correct
5 Halted 0 ms 0 KB -