Submission #725464

# Submission time Handle Problem Language Result Execution time Memory
725464 2023-04-17T13:26:34 Z buffering Exhibition (JOI19_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

void IO(string s = "")
{
    if (s == "")
    {
        freopen("input.txt", "r", stdin);
        freopen("output 2.txt", "w", stdout);
    }
    if (s != "")
    {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}
bool check(int k, vector<pair<int, int>>& p, vector<int>& frames) {
    if (k > frames.size()) return false;
    vector<int> sizes;
    for (int i = frames.size() - k; i < frames.size(); i++) {
        sizes.push_back(frames[i]);
    }
    bool works = true; int pointer = 0;
    for (int i = 0; i < k; i++) {
        while (p[pointer].second > sizes[i]) {
            if (pointer == p.size()) {
                works = false; 
                break;
            }
            pointer++;
        }
        pointer++;
        if (pointer >= p.size() && i != k - 1) {
            works = false;
            break;
        }
    }
    return works;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    //IO();

    /*
    Binary search for answer

    If x is k, choose suffix of sizes for frames 

    For each i in suffix, choose frame with size <= i with least value
    */

    int n; int m;
    cin >> n >> m;

    vector<pair<int, int>> p(n);
    vector<int> frames(m);

    for (int i = 0; i < n; i++) {
        cin >> p[i].second >> p[i].first; //{value, size}
    }
    for (int i = 0; i < m; i++) {
        cin >> frames[i];
    }
    sort(p.begin(), p.end());
    sort(frames.begin(), frames.end());

    int lo = 0; int hi = min(n, m);
    while (lo <= hi) {
        int mid = (lo + hi)/2;
        if (check(mid, p, frames)) {
            if (!check(mid + 1, p, frames)) {
                cout << mid << endl;
                return 0;
            }
            else lo = mid + 1;
        }
        else hi = mid - 1;
    }

}

Compilation message

joi2019_ho_t2.cpp: In function 'bool check(int, std::vector<std::pair<int, int> >&, std::vector<int>&)':
joi2019_ho_t2.cpp:18:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     if (k > frames.size()) return false;
      |         ~~^~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:20:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = frames.size() - k; i < frames.size(); i++) {
      |                                     ~~^~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:26:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if (pointer == p.size()) {
      |                 ~~~~~~~~^~~~~~~~~~~
joi2019_ho_t2.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (pointer >= p.size() && i != k - 1) {
      |             ~~~~~~~~^~~~~~~~~~~
joi2019_ho_t2.cpp: In function 'void IO(std::string)':
joi2019_ho_t2.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.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 + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -