답안 #793918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793918 2023-07-26T08:05:28 Z vjudge1 Passport (JOI23_passport) C++14
22 / 100
2000 ms 34292 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const int N = 2e5 ;
int n, q, l[N + 1], r[N + 1], x[N + 1] ;
int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    for(int i = 1 ; i <= n ; i++)
        cin >> l[i] >> r[i] ;
    cin >> q ;
    for(int i = 1 ; i <= q ; i++)
        cin >> x[i] ;
    if(q == 1 && x[1] == 1)
    {
        int ans = 0, mx = r[1], ind = 1 ;
        while(ind < n)
        {
            int mx1 = 0 ;
            for(int j = ind ; j <= mx ; j++)
                mx1 = max(mx1, r[j]) ;
            ans++ ;
            ind = mx ;
            if(mx1 == mx)
                break ;
            mx = max(mx1, mx) ;
        }
        if(ind < n)
            ans = -1 ;
        cout << ans ;
        return 0 ;
    }
    if(q == 1 && n <= 2500)
    {
        int ans[n + 1][n + 1] ;
        for(int i = 1 ; i <= n ; i++)
            for(int j = 1 ; j <= n ; j++)
                ans[i][j] = 1e9 ;
        set<pair<int, pair<int, int>>> s ;
        s.insert({1, {l[x[1]], r[x[1]]}}) ;
        ans[l[x[1]]][r[x[1]]] = 1 ;
        while(s.size())
        {
            auto j = *s.begin() ;
            int cnt = j.fi, ln = j.se.fi, rn = j.se.se ;
            s.erase(j) ;
            if(cnt > ans[ln][rn])
                continue ;
            for(int q = ln ; q <= rn ; q++)
            {
                int lch = min(ln, l[q]), rch = max(rn, r[q]), cntch = cnt + 1 ;
                if(cntch < ans[lch][rch])
                {
                    ans[lch][rch] = cntch ;
                    s.insert({cntch, {lch, rch}}) ;
                }
            }
        }
        if(ans[1][n] == 1e9)ans[1][n] = -1 ;
        cout << ans[1][n] ;
        return 0 ;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 24 ms 1812 KB Output is correct
5 Correct 23 ms 1768 KB Output is correct
6 Correct 24 ms 1868 KB Output is correct
7 Correct 19 ms 1832 KB Output is correct
8 Correct 23 ms 1600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1057 ms 34292 KB Output is correct
17 Correct 851 ms 24872 KB Output is correct
18 Correct 27 ms 24788 KB Output is correct
19 Correct 53 ms 23636 KB Output is correct
20 Execution timed out 2066 ms 24860 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1057 ms 34292 KB Output is correct
17 Correct 851 ms 24872 KB Output is correct
18 Correct 27 ms 24788 KB Output is correct
19 Correct 53 ms 23636 KB Output is correct
20 Execution timed out 2066 ms 24860 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 24 ms 1812 KB Output is correct
5 Correct 23 ms 1768 KB Output is correct
6 Correct 24 ms 1868 KB Output is correct
7 Correct 19 ms 1832 KB Output is correct
8 Correct 23 ms 1600 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 1057 ms 34292 KB Output is correct
25 Correct 851 ms 24872 KB Output is correct
26 Correct 27 ms 24788 KB Output is correct
27 Correct 53 ms 23636 KB Output is correct
28 Execution timed out 2066 ms 24860 KB Time limit exceeded
29 Halted 0 ms 0 KB -