답안 #1087533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087533 2024-09-12T21:17:55 Z Noname_1900 쌀 창고 (IOI11_ricehub) C++17
100 / 100
14 ms 1884 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
  int nbRiz = R, maxPos = L;
  long long argent = B;
  //vector<pair<int, int>>
  int debTaille = 1, finTaille = nbRiz+1;
  while(debTaille < finTaille-1)
  {
  //  cout << debTaille << " " << finTaille << " : ";
      int milieu = (debTaille+finTaille)/2;
   //   cout << milieu << endl;
      int mediane = X[(milieu-1)/2];
      bool marche = false;
      long long combienCout = 0;

      for(int i = 0; i < milieu; i++)
      {
        combienCout += abs(mediane-X[i]);
      }
    //  cout << mediane<< " " << combienCout << endl;
      if(combienCout <= argent)
      {
        debTaille = milieu;
        continue;
      }
      for(int i = milieu; i < nbRiz; i++)
      {
        int ancMEdiane = mediane;
          
          
          mediane = X[(i+(i-milieu+1))/2];
          combienCout -= abs(ancMEdiane-X[i-milieu]);
          combienCout += abs(mediane-X[i]);
          if(milieu % 2 == 0) combienCout -= abs(mediane-ancMEdiane);
          //combienCout += abs(ancMEdiane-mediane);
        //  |c||||a|||||c|
      //  cout << mediane<< " " << combienCout << endl;
          if(combienCout <= argent)
          {
            debTaille = milieu;
            marche = true;
            break;
          }
      }
      if(!marche)
        finTaille = milieu;
  }
  return debTaille;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:6:18: warning: unused variable 'maxPos' [-Wunused-variable]
    6 |   int nbRiz = R, maxPos = L;
      |                  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
9 Correct 1 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 428 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 444 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 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 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 348 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 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 10 ms 1880 KB Output is correct
5 Correct 5 ms 1112 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 9 ms 1372 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 5 ms 860 KB Output is correct
10 Correct 5 ms 820 KB Output is correct
11 Correct 14 ms 1884 KB Output is correct
12 Correct 10 ms 1884 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 5 ms 860 KB Output is correct
15 Correct 7 ms 1372 KB Output is correct
16 Correct 7 ms 1372 KB Output is correct
17 Correct 11 ms 1676 KB Output is correct
18 Correct 9 ms 1628 KB Output is correct
19 Correct 9 ms 1816 KB Output is correct
20 Correct 10 ms 1816 KB Output is correct