Submission #1103605

# Submission time Handle Problem Language Result Execution time Memory
1103605 2024-10-21T11:42:17 Z 12345678 Fire (BOI24_fire) C++17
0 / 100
2000 ms 13736 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=2e5+5;

ll n, m, nxt[nx], inv[nx], vs[nx], ans=-1, cnt;
pair<ll, ll> vl[nx];
vector<ll> d[nx];

bool dfs(int u)
{
    int in=0;
    vs[u]=1;
    for (auto v:d[u])
    {
        if (vs[v]==2) continue;
        if (vs[v]==1) return cnt++, vs[u]=vs[v]=2, 1;
        in=in||dfs(v);
    }
    if (vs[u]==2) return cnt++, 0;
    vs[u]=2;
    if (in) return cnt++, 1;
    return 0;
}

ll compare(int x, int y)
{
    pair<int, int> px=vl[x], py=vl[y];
    if (inv[x]) px.second+=m, py.first+=m, py.second+=m;
    if (inv[y]) py.second+=m;
    if (px.first<=py.first&&py.first<=px.second&&py.second>px.second) return py.second;
    return -1;
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>vl[i].first>>vl[i].second, inv[i]=vl[i].second<vl[i].first;
    for (int i=1; i<=n; i++)
    {
        pair<int, int> mx={-1, -1};
        for (int j=1; j<=n; j++) mx=max(mx, {compare(i, j), j});
        if (mx.first!=-1) d[mx.second].push_back(i);
        //cout<<"debug "<<i<<' '<<mx.second<<'\n';
    }
    for (int i=1; i<=n; i++) if (!vs[i]) cnt=0, dfs(i), ans=max(ans, cnt?cnt:-1);
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Correct 2 ms 8784 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8856 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Correct 2 ms 8784 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8856 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Correct 2 ms 8784 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8856 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8784 KB Output is correct
2 Correct 2 ms 8856 KB Output is correct
3 Correct 3 ms 9040 KB Output is correct
4 Correct 2 ms 8784 KB Output is correct
5 Correct 2 ms 8616 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8784 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Correct 2 ms 8784 KB Output is correct
10 Correct 3 ms 8856 KB Output is correct
11 Correct 3 ms 8784 KB Output is correct
12 Correct 3 ms 8784 KB Output is correct
13 Correct 2 ms 8784 KB Output is correct
14 Correct 2 ms 8784 KB Output is correct
15 Correct 135 ms 8968 KB Output is correct
16 Correct 147 ms 9180 KB Output is correct
17 Correct 185 ms 9032 KB Output is correct
18 Correct 109 ms 9220 KB Output is correct
19 Correct 106 ms 8964 KB Output is correct
20 Execution timed out 2052 ms 13736 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Incorrect 2 ms 8784 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8784 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Correct 2 ms 8784 KB Output is correct
5 Correct 2 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8856 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -