Submission #781902

# Submission time Handle Problem Language Result Execution time Memory
781902 2023-07-13T12:58:11 Z YassineBenYounes Passport (JOI23_passport) C++17
40 / 100
2000 ms 25096 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;
    while(q--){
        memset(dp, -1, sizeof dp);
        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);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 24788 KB Output is correct
2 Correct 10 ms 24788 KB Output is correct
3 Correct 10 ms 24772 KB Output is correct
4 Runtime error 2 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24776 KB Output is correct
2 Correct 11 ms 24908 KB Output is correct
3 Correct 9 ms 24780 KB Output is correct
4 Correct 9 ms 24788 KB Output is correct
5 Correct 10 ms 24788 KB Output is correct
6 Correct 11 ms 24828 KB Output is correct
7 Correct 10 ms 24860 KB Output is correct
8 Correct 10 ms 24856 KB Output is correct
9 Correct 10 ms 24804 KB Output is correct
10 Correct 11 ms 24776 KB Output is correct
11 Correct 12 ms 24788 KB Output is correct
12 Correct 13 ms 24788 KB Output is correct
13 Correct 10 ms 24860 KB Output is correct
14 Correct 10 ms 24788 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24776 KB Output is correct
2 Correct 11 ms 24908 KB Output is correct
3 Correct 9 ms 24780 KB Output is correct
4 Correct 9 ms 24788 KB Output is correct
5 Correct 10 ms 24788 KB Output is correct
6 Correct 11 ms 24828 KB Output is correct
7 Correct 10 ms 24860 KB Output is correct
8 Correct 10 ms 24856 KB Output is correct
9 Correct 10 ms 24804 KB Output is correct
10 Correct 11 ms 24776 KB Output is correct
11 Correct 12 ms 24788 KB Output is correct
12 Correct 13 ms 24788 KB Output is correct
13 Correct 10 ms 24860 KB Output is correct
14 Correct 10 ms 24788 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
16 Correct 1189 ms 24916 KB Output is correct
17 Correct 520 ms 24916 KB Output is correct
18 Correct 19 ms 24916 KB Output is correct
19 Correct 30 ms 24916 KB Output is correct
20 Correct 1647 ms 25096 KB Output is correct
21 Correct 726 ms 25092 KB Output is correct
22 Correct 10 ms 24916 KB Output is correct
23 Correct 1117 ms 24996 KB Output is correct
24 Correct 625 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24776 KB Output is correct
2 Correct 11 ms 24908 KB Output is correct
3 Correct 9 ms 24780 KB Output is correct
4 Correct 9 ms 24788 KB Output is correct
5 Correct 10 ms 24788 KB Output is correct
6 Correct 11 ms 24828 KB Output is correct
7 Correct 10 ms 24860 KB Output is correct
8 Correct 10 ms 24856 KB Output is correct
9 Correct 10 ms 24804 KB Output is correct
10 Correct 11 ms 24776 KB Output is correct
11 Correct 12 ms 24788 KB Output is correct
12 Correct 13 ms 24788 KB Output is correct
13 Correct 10 ms 24860 KB Output is correct
14 Correct 10 ms 24788 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
16 Correct 1189 ms 24916 KB Output is correct
17 Correct 520 ms 24916 KB Output is correct
18 Correct 19 ms 24916 KB Output is correct
19 Correct 30 ms 24916 KB Output is correct
20 Correct 1647 ms 25096 KB Output is correct
21 Correct 726 ms 25092 KB Output is correct
22 Correct 10 ms 24916 KB Output is correct
23 Correct 1117 ms 24996 KB Output is correct
24 Correct 625 ms 24916 KB Output is correct
25 Correct 18 ms 24788 KB Output is correct
26 Correct 15 ms 24788 KB Output is correct
27 Execution timed out 2065 ms 24916 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 24788 KB Output is correct
2 Correct 10 ms 24788 KB Output is correct
3 Correct 10 ms 24772 KB Output is correct
4 Runtime error 2 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -