답안 #1103607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103607 2024-10-21T11:44:05 Z 12345678 Fire (BOI24_fire) C++17
0 / 100
2000 ms 12956 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[i].push_back(mx.second);
        //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;
}
# 결과 실행 시간 메모리 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 8952 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 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 8952 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 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 8952 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 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8820 KB Output is correct
3 Correct 2 ms 8784 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8848 KB Output is correct
8 Correct 2 ms 8784 KB Output is correct
9 Correct 2 ms 8784 KB Output is correct
10 Correct 2 ms 8784 KB Output is correct
11 Correct 2 ms 8784 KB Output is correct
12 Correct 2 ms 8784 KB Output is correct
13 Correct 3 ms 8784 KB Output is correct
14 Correct 2 ms 8952 KB Output is correct
15 Correct 104 ms 9168 KB Output is correct
16 Correct 97 ms 9136 KB Output is correct
17 Correct 179 ms 9032 KB Output is correct
18 Correct 97 ms 9032 KB Output is correct
19 Correct 104 ms 8784 KB Output is correct
20 Execution timed out 2056 ms 12956 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8784 KB Output is correct
2 Correct 2 ms 8816 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 -
# 결과 실행 시간 메모리 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 8952 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 Incorrect 2 ms 8784 KB Output isn't correct
10 Halted 0 ms 0 KB -