답안 #1090691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090691 2024-09-18T15:29:54 Z BigBadBully Fire (BOI24_fire) C++17
13 / 100
63 ms 15040 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;
 
 
int solve2(int n,int m,vector<pii> v)
{
    
    for (int i = 0; i< n; i++)
    {
        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;
    }
    {
    vector<bool> del(n);
    int mini = v[n-1].ss;
    for (int i = n-1; i >= 0;i--)
    {
        if (v[i].ff >= mini)
            del[i] = 1;
        mini = min(mini,v[i].ff);
    }
    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;
    /*for (int i = 0; i < n; i++)
        cout << v[i].ff << ' ' << v[i].ss << '\n';*/
    int prev = v[0].ss;
    int used = 1;
    if (v[0].ff != 0)
    {
        return -1;
    }
    for (int i = 1; i < n; i++)
    {
        if (v[i].ff > prev)
        {
            used++;
            prev = v[i-1].ss;
            if (v[i].ff > prev)
            {
                return -1;
            }
        }
        if (prev != 0 && v[i].ss == 0)
        {
            used++;
            prev = inf;
            break;
        }
    }
    if(prev == inf)
    return used;
    else
    return -1;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector<pii> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].ff >> v[i].ss;
    cout << solve2(n,m,v) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 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 1 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 776 KB Output is correct
16 Correct 2 ms 780 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 780 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 23 ms 6488 KB Output is correct
21 Correct 63 ms 7500 KB Output is correct
22 Correct 43 ms 7384 KB Output is correct
23 Correct 54 ms 14220 KB Output is correct
24 Correct 50 ms 13996 KB Output is correct
25 Correct 43 ms 7892 KB Output is correct
26 Correct 46 ms 10680 KB Output is correct
27 Correct 45 ms 15040 KB Output is correct
28 Correct 61 ms 7156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 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 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -