답안 #1080257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080257 2024-08-29T08:23:35 Z raphaelp Fire (BOI24_fire) C++14
0 / 100
1 ms 436 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> Tab;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        if (r >= l)
        {
            Tab.push_back({l, r, i});
            Tab.push_back({l + M, r + M, i});
        }
        else
        {
            Tab.push_back({l, r + M, i});
        }
    }
    sort(Tab.begin(), Tab.end());
    int last = -1;
    vector<int> removed(Tab.size());
    for (int i = 0; i < Tab.size(); i++)
    {
        if (last != -1)
        {
            if (Tab[last][1] >= Tab[i][1])
                removed[i] = 1;
        }
        if (removed[i] == 0)
            last = i;
    }
    vector<vector<int>> Tab2;
    for (int i = 0; i < Tab.size(); i++)
        if (!removed[i])
            Tab2.push_back(Tab[i]);
    swap(Tab, Tab2);
    vector<int> next(N, -1);
    for (int i = Tab.size() - 1; i >= 0; i--)
    {
        int x = lower_bound(Tab.begin(), Tab.end(), vector<int>{Tab[i][1] + 1}) - Tab.begin() - 1;
        if (x != i)
            next[Tab[i][2]] = Tab[x][2];
    }
    vector<int> occ(N, -1);
    int best = 1000000000;
    int compte = 0;
    for (int i = 0; i < N; i++)
    {
        if (occ[i] != -1)
            continue;
        if (next[i] == -1)
            continue;
        int x = i;
        while (occ[x] == -1 && x != -1)
        {
            occ[x] = compte;
            compte++;
            x = next[x];
        }
        if (x != -1)
            best = min(best, compte - occ[x]);
    }
    cout << ((best == 1000000000) ? -1 : best);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < Tab.size(); i++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < Tab.size(); i++)
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 Incorrect 0 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 Incorrect 0 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 Incorrect 0 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 Incorrect 0 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -