Submission #1039181

# Submission time Handle Problem Language Result Execution time Memory
1039181 2024-07-30T14:14:56 Z Mr_Ph Fire (BOI24_fire) C++17
40 / 100
280 ms 258420 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int mod=(int)1e9+7;
int p[900003][23];
vector<int>lol;
void solve()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>arr;
    vector<int>hi;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        hi.push_back(a);
        hi.push_back(b);
        hi.push_back(a+1);
        hi.push_back(b+1);
        arr.push_back({a,b});
    }
    hi.push_back(m);
    hi.push_back(m+1);
    sort(hi.begin(),hi.end());
    hi.erase(unique(hi.begin(),hi.end()),hi.end());
    m=lower_bound(hi.begin(),hi.end(),m)-hi.begin();
    for(int i=0;i<n;i++)
    {
        arr[i].first=lower_bound(hi.begin(),hi.end(),arr[i].first)-hi.begin();
        arr[i].second=lower_bound(hi.begin(),hi.end(),arr[i].second)-hi.begin();
    }
    // for(auto i:arr)cout<<i.first<<" "<<i.second<<endl;
    vector<vector<int>>ls(2*m+5);
    for(int i=0;i<n;i++)
    {
        if(arr[i].first>arr[i].second)arr[i].second+=m;
        p[arr[i].first][0]=max(p[arr[i].first][0],arr[i].second+1);
    }
    for(int i=0;i<2*m;i++)p[i][0]=max(p[i-1][0],p[i][0]);
    for(int i=1;i<=20;i++)
        for(int j=0;j<2*m;j++)
            p[j][i]=p[p[j][i-1]][i-1];
    int fans=1e9;
    for(int i=0;i<m;i++)
    {
        int cnt=0,cur=i;
        for(int j=20;j>=0;j--)
        {
            if(p[cur][j]<=i+m)
            {
                cur=p[cur][j];
                cnt+=(1ll<<j);
            }
        }
        if(p[cur][0]<=i+m)continue;
        cnt++;
        // cout<<i<<" "<<cnt<<" "<<cur<<" "<<p[cur][0]<<" "<<p[i][0]<<endl;
        fans=min(fans,cnt);
    }
    if(fans==1e9)cout<<-1<<endl;
    else cout<<fans<<endl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 1 ms 348 KB Output is correct
9 Correct 0 ms 376 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 0 ms 412 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 1 ms 348 KB Output is correct
9 Correct 0 ms 376 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 0 ms 412 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 608 KB Output is correct
34 Correct 1 ms 608 KB Output is correct
35 Correct 1 ms 608 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 0 ms 608 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 1 ms 348 KB Output is correct
9 Correct 0 ms 376 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 0 ms 412 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 608 KB Output is correct
34 Correct 1 ms 608 KB Output is correct
35 Correct 1 ms 608 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 0 ms 608 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 7 ms 5208 KB Output is correct
40 Correct 7 ms 5212 KB Output is correct
41 Correct 7 ms 5208 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2396 KB Output is correct
44 Correct 5 ms 2908 KB Output is correct
45 Correct 5 ms 2904 KB Output is correct
46 Correct 5 ms 2908 KB Output is correct
47 Correct 7 ms 5188 KB Output is correct
48 Correct 7 ms 5212 KB Output is correct
49 Correct 4 ms 2776 KB Output is correct
50 Correct 4 ms 2908 KB Output is correct
# Verdict Execution time Memory 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 344 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 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 7 ms 5212 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2392 KB Output is correct
18 Correct 4 ms 2908 KB Output is correct
19 Correct 6 ms 5136 KB Output is correct
20 Correct 34 ms 8004 KB Output is correct
21 Runtime error 253 ms 258364 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 464 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 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 728 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 7 ms 5208 KB Output is correct
13 Correct 5 ms 2908 KB Output is correct
14 Correct 4 ms 2908 KB Output is correct
15 Correct 34 ms 8784 KB Output is correct
16 Correct 232 ms 101460 KB Output is correct
17 Runtime error 280 ms 258420 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 1 ms 348 KB Output is correct
9 Correct 0 ms 376 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 0 ms 412 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 608 KB Output is correct
34 Correct 1 ms 608 KB Output is correct
35 Correct 1 ms 608 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 0 ms 608 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 7 ms 5208 KB Output is correct
40 Correct 7 ms 5212 KB Output is correct
41 Correct 7 ms 5208 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2396 KB Output is correct
44 Correct 5 ms 2908 KB Output is correct
45 Correct 5 ms 2904 KB Output is correct
46 Correct 5 ms 2908 KB Output is correct
47 Correct 7 ms 5188 KB Output is correct
48 Correct 7 ms 5212 KB Output is correct
49 Correct 4 ms 2776 KB Output is correct
50 Correct 4 ms 2908 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 0 ms 604 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 620 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 7 ms 5212 KB Output is correct
66 Correct 4 ms 2908 KB Output is correct
67 Correct 4 ms 2392 KB Output is correct
68 Correct 4 ms 2908 KB Output is correct
69 Correct 6 ms 5136 KB Output is correct
70 Correct 34 ms 8004 KB Output is correct
71 Runtime error 253 ms 258364 KB Execution killed with signal 11
72 Halted 0 ms 0 KB -