Submission #1031087

# Submission time Handle Problem Language Result Execution time Memory
1031087 2024-07-22T14:40:59 Z Abito Fire (BOI24_fire) C++17
31 / 100
2000 ms 616 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int L[N],R[N],n,m;
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>m;int ans=INT_MAX;
    for (int i=1;i<=n;i++) cin>>L[i]>>R[i];
    for (int k=1;k<=n;k++){
        int x=L[k];
        //cout<<x<<endl;
        vector<pair<int,int>> a;
        vector<int> p(n);
        for (int i=1;i<=n;i++){
            int l=(L[i]-x+m)%m,r=(R[i]-x+m)%m;
            //cout<<l<<' '<<r<<endl;
            if (l>r) r=m-1;
            a.pb({l,r});
        }
        sort(a.begin(),a.end());
        /*for (auto u:a) cout<<u.F<<' ';cout<<endl;
        for (auto u:a) cout<<u.S<<' ';cout<<endl;
        cout<<endl;*/
        p[0]=a[0].S;
        for (int i=1;i<n;i++) p[i]=max(p[i-1],a[i].S);
        int cur=0,ansx=0;
        while (cur<m-1){
            int l=0,r=n-1,mid,idx=-1;
            while (l<=r){
                mid=(l+r)/2;
                if (a[mid].F<=cur){
                    idx=mid;
                    l=mid+1;
                }else r=mid-1;
            }
            if (idx==-1){
                ansx=INT_MAX;
                break;
            }
            if (p[idx]==cur){
                ansx=INT_MAX;
                break;
            }
            ansx++;
            cur=p[idx];
        }
        ans=min(ans,ansx);
    }
    if (ans==INT_MAX) ans=-1;
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 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 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 1 ms 344 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 1 ms 600 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 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 1 ms 344 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 1 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 5 ms 372 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 480 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 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 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 1 ms 344 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 1 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 5 ms 372 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 480 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
39 Correct 1425 ms 608 KB Output is correct
40 Execution timed out 2065 ms 604 KB Time limit exceeded
41 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 348 KB Output is correct
5 Correct 1 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 5 ms 348 KB Output is correct
10 Correct 4 ms 476 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 5 ms 472 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 1351 ms 616 KB Output is correct
16 Execution timed out 2011 ms 600 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 5 ms 348 KB Output is correct
9 Correct 5 ms 348 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 1419 ms 616 KB Output is correct
13 Execution timed out 2061 ms 604 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 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 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 1 ms 344 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 1 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 5 ms 372 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 480 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
39 Correct 1425 ms 608 KB Output is correct
40 Execution timed out 2065 ms 604 KB Time limit exceeded
41 Halted 0 ms 0 KB -