답안 #781904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781904 2023-07-13T13:00:02 Z YassineBenYounes Passport (JOI23_passport) C++17
40 / 100
2000 ms 25112 KB
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd  pair<double,double>
#define vdd  vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////

void usaco_problem(){
    freopen("milkvisits.in", "r", stdin);
    freopen("milkvisits.out", "w", stdout);
}

void init(){
    #ifndef ONLINE_JUDGE
 
freopen("input.txt", "r", stdin);
 
freopen("output.txt", "w", stdout);
 
#endif // ONLINE_JUDGE
}

const int mx = 2505;
const int LOG = 25;
const ll inf = 1e18;
const ll mod = 1e8;
int n;
int r[mx], l[mx];
int dp[mx][mx];
int solve(int a, int b){
    if(a == 0 && b == n-1)return 0;
    if(dp[a][b] != -1)return dp[a][b];
    int x = 1e9;
    for(int i = a; i <= b;i++){
        if(min(a, l[i]) == a && max(b, r[i]) == b)continue;
        x = min(x, solve(min(a, l[i]), max(b, r[i])) + 1);
    }
    return dp[a][b] = x;
}
void run_case(){
    cin >> n;
    for(int i = 0; i < n;i++){
        cin >> l[i] >> r[i];
        l[i]--;r[i]--;
    }
    int q;cin >> q;
    memset(dp, -1, sizeof dp);
    while(q--){
        int a;cin >> a;
        a--;
        int res = solve(a, a);
        cout << (res == 1e9 ? -1 : res) << endl;
    }
}

int main(){
    speed;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        run_case();
    }
}

/*
    NEVER GIVE UP!
    DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
    Your Guide when stuck:
    - Continue keyword only after reading the whole input
    - Don't use memset with testcases
    - Check for corner cases(n=1, n=0)
    - Check where you declare n(Be careful of declaring it globally and in main)
*/

Compilation message

passport.cpp: In function 'void usaco_problem()':
passport.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp: In function 'void init()':
passport.cpp:39:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:41:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24788 KB Output is correct
2 Correct 9 ms 24828 KB Output is correct
3 Correct 10 ms 24788 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24788 KB Output is correct
2 Correct 9 ms 24768 KB Output is correct
3 Correct 9 ms 24848 KB Output is correct
4 Correct 10 ms 24788 KB Output is correct
5 Correct 12 ms 24788 KB Output is correct
6 Correct 12 ms 24788 KB Output is correct
7 Correct 11 ms 24788 KB Output is correct
8 Correct 9 ms 24788 KB Output is correct
9 Correct 10 ms 24796 KB Output is correct
10 Correct 10 ms 24844 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 10 ms 24896 KB Output is correct
13 Correct 8 ms 24892 KB Output is correct
14 Correct 8 ms 24788 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24788 KB Output is correct
2 Correct 9 ms 24768 KB Output is correct
3 Correct 9 ms 24848 KB Output is correct
4 Correct 10 ms 24788 KB Output is correct
5 Correct 12 ms 24788 KB Output is correct
6 Correct 12 ms 24788 KB Output is correct
7 Correct 11 ms 24788 KB Output is correct
8 Correct 9 ms 24788 KB Output is correct
9 Correct 10 ms 24796 KB Output is correct
10 Correct 10 ms 24844 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 10 ms 24896 KB Output is correct
13 Correct 8 ms 24892 KB Output is correct
14 Correct 8 ms 24788 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 1175 ms 24880 KB Output is correct
17 Correct 545 ms 24916 KB Output is correct
18 Correct 23 ms 24924 KB Output is correct
19 Correct 27 ms 24888 KB Output is correct
20 Correct 1703 ms 25068 KB Output is correct
21 Correct 780 ms 25072 KB Output is correct
22 Correct 10 ms 24788 KB Output is correct
23 Correct 1187 ms 24972 KB Output is correct
24 Correct 638 ms 25044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24788 KB Output is correct
2 Correct 9 ms 24768 KB Output is correct
3 Correct 9 ms 24848 KB Output is correct
4 Correct 10 ms 24788 KB Output is correct
5 Correct 12 ms 24788 KB Output is correct
6 Correct 12 ms 24788 KB Output is correct
7 Correct 11 ms 24788 KB Output is correct
8 Correct 9 ms 24788 KB Output is correct
9 Correct 10 ms 24796 KB Output is correct
10 Correct 10 ms 24844 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 10 ms 24896 KB Output is correct
13 Correct 8 ms 24892 KB Output is correct
14 Correct 8 ms 24788 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 1175 ms 24880 KB Output is correct
17 Correct 545 ms 24916 KB Output is correct
18 Correct 23 ms 24924 KB Output is correct
19 Correct 27 ms 24888 KB Output is correct
20 Correct 1703 ms 25068 KB Output is correct
21 Correct 780 ms 25072 KB Output is correct
22 Correct 10 ms 24788 KB Output is correct
23 Correct 1187 ms 24972 KB Output is correct
24 Correct 638 ms 25044 KB Output is correct
25 Correct 10 ms 24788 KB Output is correct
26 Correct 13 ms 24808 KB Output is correct
27 Correct 1695 ms 24884 KB Output is correct
28 Correct 1086 ms 24972 KB Output is correct
29 Execution timed out 2077 ms 25112 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24788 KB Output is correct
2 Correct 9 ms 24828 KB Output is correct
3 Correct 10 ms 24788 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -