답안 #897978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897978 2024-01-04T06:37:13 Z vjudge1 Passport (JOI23_passport) C++17
46 / 100
1547 ms 25172 KB
// MDSPro
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const ld PI = 3.141592653589793;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFLL = 4e18;
const double EPS = 1e-9;
const int MAXN = 1000*1007;

void solve(int NT){
    int n; cin >> n;
    vector<pair<int, int>> v = {{0, 0}};
    for(int i = 1; i <= n; ++i) {
        int x, y; cin >> x >> y;
        v.emplace_back(x, y);
    }

    int q; cin >> q;
    int x; cin >> x;
    if(x == 1) {
        vector<int> opening(n + 1, 0);
        for(int i = 1; i <= n; ++i) {
            opening[i] = max(opening[i], v[i].second);
        }

        int cur = 0, til = 1, ans = 0;
        while(til < n) {
            int ntil = til;
            for(int i = cur + 1; i <= til; ++i) {
                ntil = max(ntil, opening[i]);
            }

            if(ntil == til) break;
            cur = til;
            til = ntil;
            ans++;
        }
        if(til != n) ans = -1;
        cout << ans;
    } else {
        vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
        dp[x][x] = 0;
        for(int r = 1; r <= n; ++r) {
            for(int l = r; l >= 1; --l) {
                if(dp[l][r] != INF) {
                    for(int m = l; m <= r; ++m) {
                        int nl = min(l, v[m].first);
                        int nr = max(r, v[m].second);
                        if(nl != l || r != nr) {
                            dp[nl][nr] = min(dp[nl][nr], dp[l][r] + 1);
                        } 
                    }
                }
            }
        }

        if(dp[1][n] == INF) dp[1][n] = -1;
        cout << dp[1][n];
    }
}

// #define TESTCASES
int main() {
    cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    #ifdef TESTCASES
        cin >> t;
    #endif
    
    for(int i = 1; i <= t; ++i){
        solve(i);
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 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 25 ms 5048 KB Output is correct
5 Correct 25 ms 5068 KB Output is correct
6 Correct 26 ms 5332 KB Output is correct
7 Correct 20 ms 4300 KB Output is correct
8 Correct 19 ms 4044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 901 ms 22100 KB Output is correct
17 Correct 488 ms 24808 KB Output is correct
18 Correct 37 ms 24924 KB Output is correct
19 Correct 39 ms 23688 KB Output is correct
20 Correct 1547 ms 25084 KB Output is correct
21 Correct 670 ms 25172 KB Output is correct
22 Correct 22 ms 25084 KB Output is correct
23 Correct 765 ms 25068 KB Output is correct
24 Correct 457 ms 25168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 901 ms 22100 KB Output is correct
17 Correct 488 ms 24808 KB Output is correct
18 Correct 37 ms 24924 KB Output is correct
19 Correct 39 ms 23688 KB Output is correct
20 Correct 1547 ms 25084 KB Output is correct
21 Correct 670 ms 25172 KB Output is correct
22 Correct 22 ms 25084 KB Output is correct
23 Correct 765 ms 25068 KB Output is correct
24 Correct 457 ms 25168 KB Output is correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 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 25 ms 5048 KB Output is correct
5 Correct 25 ms 5068 KB Output is correct
6 Correct 26 ms 5332 KB Output is correct
7 Correct 20 ms 4300 KB Output is correct
8 Correct 19 ms 4044 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 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 2 ms 756 KB Output is correct
24 Correct 901 ms 22100 KB Output is correct
25 Correct 488 ms 24808 KB Output is correct
26 Correct 37 ms 24924 KB Output is correct
27 Correct 39 ms 23688 KB Output is correct
28 Correct 1547 ms 25084 KB Output is correct
29 Correct 670 ms 25172 KB Output is correct
30 Correct 22 ms 25084 KB Output is correct
31 Correct 765 ms 25068 KB Output is correct
32 Correct 457 ms 25168 KB Output is correct
33 Incorrect 1 ms 348 KB Output isn't correct
34 Halted 0 ms 0 KB -