답안 #888661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888661 2023-12-18T05:14:44 Z vjudge1 Passport (JOI23_passport) C++17
0 / 100
474 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <int> L(n), R(n);
    for ( int i = 0; i < n; i++ ){
        cin >> L[i] >> R[i];
        --L[i], --R[i];
    }
    int qq, s; cin >> qq >> s;
    --s;
    const int inf = 1e15;
    vector <vector<int>> dp(n, vector <int> (n, -1));
    dp[L[s]][R[s]] = 1;
    auto dfs = [&](auto dfs, int l, int r) -> int{
        if ( l > r ){
            return inf;
        }
        int &ret = dp[l][r];
        if ( dp[l][r] != -1 ){
            return ret;
        } ret = inf;
        for ( int i = l; i <= r; i++ ){
            bool ok = false, fl = false;
            for ( int j = i; j <= r; j++ ){
                if ( R[j] >= r ) ok = true;
                if ( L[j] <= l ) fl = true;
                if ( (ok & fl) && (i != l || j != r) ){
                    auto flag = chmin(ret, dfs(dfs, i, j) + 1);
                }
            }
        }
        return ret;
    };
    int ans = dfs(dfs, 0, n - 1);
    if ( ans == inf ){
        ans = -1;
    }
    cout << ans;

    cout << '\n';
}

Compilation message

passport.cpp: In instantiation of 'main()::<lambda(auto:23, long long int, long long int)> [with auto:23 = main()::<lambda(auto:23, long long int, long long int)>]':
passport.cpp:66:32:   required from here
passport.cpp:60:26: warning: unused variable 'flag' [-Wunused-variable]
   60 |                     auto flag = chmin(ret, dfs(dfs, i, j) + 1);
      |                          ^~~~
# 결과 실행 시간 메모리 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 Runtime error 474 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 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 Runtime error 474 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -