Submission #889121

# Submission time Handle Problem Language Result Execution time Memory
889121 2023-12-19T00:42:47 Z ducngo Passport (JOI23_passport) C++17
40 / 100
197 ms 214052 KB
#include <bits/stdc++.h>
#define getbit(i, j) ((i >> j) & 1)
#define maxn 200005
#define name "Passport"
using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

long long GetRandom(long long l, long long r)
{
    return uniform_int_distribution<long long> (l, r)(rng);
}

int n,q1;
int dpl[2505][2505],dpr[2505][2505];
pair<int,int> a[maxn];
int f[2505][2505];
queue<pair<int,int>> q[maxn];
void sub3()
{
    for(int i=1;i<=n;i++)
    {
        dpl[i][i]=a[i].first;
        dpr[i][i]=a[i].second;
        for(int j=i+1;j<=n;j++)
        {
            dpl[i][j]=dpl[i][j-1];
            if(dpl[i][j]>a[j].first)
            {
                dpl[i][j]=a[j].first;
            }

            dpr[i][j]=dpr[i][j-1];
            if(dpr[i][j]<a[j].second)
            {
                dpr[i][j]=a[j].second;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++) f[i][j]=1e9;
    }
    int xp;
    cin >> xp;
    int k=0;
    f[xp][xp]=0;
    q[0].push({xp,xp});
    while(k<n)
    {
        while(q[k].size())
        {
            int u=q[k].front().first,v=q[k].front().second;
//            cout<<u<<' '<<v<<' '<<f[u][v]<<' '<<dpl[u][v]<<' '<<dpr[u][v]<<'\n';
            q[k].pop();
            if(u>v) continue;
            if(f[u][v]!=k) continue;
            if(u==v)
            {
                int d=a[u].first,c=a[u].second;
                if(f[d][c]>k+1)
                {
                    f[d][c]=k+1;
                    q[k+1].push({d,c});
                }
                continue;
            }
            int d=u,c=dpr[u][v];
//            if(u==2&&v==3) cout<<d<<' '<<c<<' '<<f[d][c]<<'\n';
            if(f[d][c]>k+1)
            {
                f[d][c]=k+1;
                q[k+1].push({d,c});
            }
            d=dpl[u][v],c=v;
//            if(u==2&&v==3) cout<<d<<' '<<c<<' '<<f[d][c]<<'\n';
            if(f[d][c]>k+1)
            {
                f[d][c]=k+1;
                q[k+1].push({d,c});
            }
            d=u,c=v;
            if(d<c)
            {

                if(f[d+1][c]>k)
                {
                    f[d+1][c]=k;
                    q[k].push({d+1,c});
                }
//                if(u==2&&v==3) cout<<d<<' '<<c-1<<' '<<f[d][c-1]<<'\n';
                if(f[d][c-1]>k)
                {
                    f[d][c-1]=k;
                    q[k].push({d,c-1});
                }
            }
        }
        k++;
    }
    if(f[1][n]==1e9) cout<<-1;
    else cout<<f[1][n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(name".inp","r"))
    {
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    cin >> q1;
    if(n<=2500&&q1==1)sub3();
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
passport.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 61 ms 142020 KB Output is correct
2 Correct 61 ms 142160 KB Output is correct
3 Correct 63 ms 142160 KB Output is correct
4 Incorrect 83 ms 142416 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 141996 KB Output is correct
2 Correct 69 ms 142160 KB Output is correct
3 Correct 60 ms 142172 KB Output is correct
4 Correct 60 ms 142164 KB Output is correct
5 Correct 66 ms 142432 KB Output is correct
6 Correct 61 ms 142180 KB Output is correct
7 Correct 60 ms 142164 KB Output is correct
8 Correct 60 ms 142172 KB Output is correct
9 Correct 60 ms 142084 KB Output is correct
10 Correct 62 ms 142168 KB Output is correct
11 Correct 64 ms 148516 KB Output is correct
12 Correct 69 ms 148308 KB Output is correct
13 Correct 70 ms 148308 KB Output is correct
14 Correct 65 ms 148312 KB Output is correct
15 Correct 68 ms 148344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 141996 KB Output is correct
2 Correct 69 ms 142160 KB Output is correct
3 Correct 60 ms 142172 KB Output is correct
4 Correct 60 ms 142164 KB Output is correct
5 Correct 66 ms 142432 KB Output is correct
6 Correct 61 ms 142180 KB Output is correct
7 Correct 60 ms 142164 KB Output is correct
8 Correct 60 ms 142172 KB Output is correct
9 Correct 60 ms 142084 KB Output is correct
10 Correct 62 ms 142168 KB Output is correct
11 Correct 64 ms 148516 KB Output is correct
12 Correct 69 ms 148308 KB Output is correct
13 Correct 70 ms 148308 KB Output is correct
14 Correct 65 ms 148312 KB Output is correct
15 Correct 68 ms 148344 KB Output is correct
16 Correct 173 ms 210008 KB Output is correct
17 Correct 133 ms 210512 KB Output is correct
18 Correct 157 ms 210400 KB Output is correct
19 Correct 142 ms 209960 KB Output is correct
20 Correct 125 ms 210768 KB Output is correct
21 Correct 138 ms 210704 KB Output is correct
22 Correct 97 ms 210004 KB Output is correct
23 Correct 197 ms 214052 KB Output is correct
24 Correct 192 ms 210480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 141996 KB Output is correct
2 Correct 69 ms 142160 KB Output is correct
3 Correct 60 ms 142172 KB Output is correct
4 Correct 60 ms 142164 KB Output is correct
5 Correct 66 ms 142432 KB Output is correct
6 Correct 61 ms 142180 KB Output is correct
7 Correct 60 ms 142164 KB Output is correct
8 Correct 60 ms 142172 KB Output is correct
9 Correct 60 ms 142084 KB Output is correct
10 Correct 62 ms 142168 KB Output is correct
11 Correct 64 ms 148516 KB Output is correct
12 Correct 69 ms 148308 KB Output is correct
13 Correct 70 ms 148308 KB Output is correct
14 Correct 65 ms 148312 KB Output is correct
15 Correct 68 ms 148344 KB Output is correct
16 Correct 173 ms 210008 KB Output is correct
17 Correct 133 ms 210512 KB Output is correct
18 Correct 157 ms 210400 KB Output is correct
19 Correct 142 ms 209960 KB Output is correct
20 Correct 125 ms 210768 KB Output is correct
21 Correct 138 ms 210704 KB Output is correct
22 Correct 97 ms 210004 KB Output is correct
23 Correct 197 ms 214052 KB Output is correct
24 Correct 192 ms 210480 KB Output is correct
25 Incorrect 60 ms 138064 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 142020 KB Output is correct
2 Correct 61 ms 142160 KB Output is correct
3 Correct 63 ms 142160 KB Output is correct
4 Incorrect 83 ms 142416 KB Output isn't correct
5 Halted 0 ms 0 KB -