답안 #1039184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039184 2024-07-30T14:17:21 Z Mr_Ph Fire (BOI24_fire) C++17
40 / 100
239 ms 179928 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;
    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=1;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();
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 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
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 0 ms 604 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 0 ms 604 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 8 ms 4188 KB Output is correct
40 Correct 6 ms 4052 KB Output is correct
41 Correct 7 ms 4248 KB Output is correct
42 Correct 5 ms 2396 KB Output is correct
43 Correct 4 ms 1884 KB Output is correct
44 Correct 5 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 5 ms 2396 KB Output is correct
47 Correct 7 ms 4188 KB Output is correct
48 Correct 6 ms 4164 KB Output is correct
49 Correct 3 ms 2396 KB Output is correct
50 Correct 4 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 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 1 ms 604 KB Output is correct
15 Correct 6 ms 4188 KB Output is correct
16 Correct 4 ms 2396 KB Output is correct
17 Correct 4 ms 1884 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 6 ms 4188 KB Output is correct
20 Correct 32 ms 7388 KB Output is correct
21 Runtime error 239 ms 179076 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 4188 KB Output is correct
13 Correct 4 ms 2396 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 33 ms 7528 KB Output is correct
16 Correct 226 ms 79168 KB Output is correct
17 Runtime error 232 ms 179928 KB Execution killed with signal 11
18 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 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 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 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 0 ms 604 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 8 ms 4188 KB Output is correct
40 Correct 6 ms 4052 KB Output is correct
41 Correct 7 ms 4248 KB Output is correct
42 Correct 5 ms 2396 KB Output is correct
43 Correct 4 ms 1884 KB Output is correct
44 Correct 5 ms 2396 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 5 ms 2396 KB Output is correct
47 Correct 7 ms 4188 KB Output is correct
48 Correct 6 ms 4164 KB Output is correct
49 Correct 3 ms 2396 KB Output is correct
50 Correct 4 ms 2396 KB Output is correct
51 Correct 1 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 348 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 0 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 6 ms 4188 KB Output is correct
66 Correct 4 ms 2396 KB Output is correct
67 Correct 4 ms 1884 KB Output is correct
68 Correct 4 ms 2396 KB Output is correct
69 Correct 6 ms 4188 KB Output is correct
70 Correct 32 ms 7388 KB Output is correct
71 Runtime error 239 ms 179076 KB Execution killed with signal 11
72 Halted 0 ms 0 KB -