Submission #1090515

# Submission time Handle Problem Language Result Execution time Memory
1090515 2024-09-18T12:23:21 Z BigBadBully Fire (BOI24_fire) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
const int inf = 1e17;
const int mod = 998244353;


void solve()
{
    int n,m;
    cin >> n >> m;
    vector<pii> v(n);
    for (int i = 0; i< n; i++)
    {
        cin >> v[i].ff >> v[i].ss;
        while(v[i].ff>v[i].ss)
            v[i].ss+=m;
    }
    sort(v.begin(),v.end());
    {
    vector<bool> del(n);
    int maxi = 0;
    for (int i = 0; i < n;i ++)
    {
        if (v[i].ss <= maxi)
            del[i] = 1;
        maxi = max(maxi,v[i].ss);
    }
    vector<pii> neu;
    for (int i = 0; i < n; i++)
        if (!del[i])
            neu.push_back(v[i]);
    n = neu.size();
    v = neu;
    }
    for (int i = 0; i< n;i++)
        v[i].ss%=m;
    {
        int bigie = 0;
        for (int i = 0;i < n; i++)
            if (v[i].ff > v[i].ss)
                bigie=max(v[i].ss,bigie);
        vector<bool> del(n);
        for (int i = 0; i < n;i ++)
            if (v[i].ff < v[i].ss && v[i].ss <= bigie)
                del[i] = 1;
        vector<pii> neu;
        for (int i = 0; i < n; i++)
            if (!del[i])
                neu.push_back(v[i]);
        n = neu.size();
        v = neu;
    }
    int prev = v[0].ss;
    int used = 1;
    if (v[0].ff != 0)
    {
        cout << -1 << '\n';
        return;
    }
    for (int i = 1; i < n; i++)
    {
        if (v[i].ff > prev)
        {
            used++;
            prev = v[i-1].ss;
            if (v[i].ff > prev)
            {
                cout << -1 << '\n';
                return;
            }
        }
        if (prev != 0 && v[i].ss == 0)
        {
            used++;
            break;
        }
    }
    cout << used << '\n';
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -