답안 #793915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793915 2023-07-26T08:04:05 Z vjudge1 Passport (JOI23_passport) C++14
22 / 100
30 ms 1828 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 && n <= 300)
    {
        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 ;
    }
    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 ;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 24 ms 1756 KB Output is correct
5 Correct 27 ms 1768 KB Output is correct
6 Correct 30 ms 1828 KB Output is correct
7 Correct 19 ms 1752 KB Output is correct
8 Correct 17 ms 1456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 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 212 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 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 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 212 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 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 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 212 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 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 24 ms 1756 KB Output is correct
5 Correct 27 ms 1768 KB Output is correct
6 Correct 30 ms 1828 KB Output is correct
7 Correct 19 ms 1752 KB Output is correct
8 Correct 17 ms 1456 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 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 Incorrect 1 ms 340 KB Output isn't correct
25 Halted 0 ms 0 KB -