Submission #728443

# Submission time Handle Problem Language Result Execution time Memory
728443 2023-04-22T12:04:21 Z WKYH Rainforest Jumps (APIO21_jumps) C++14
33 / 100
4000 ms 4368 KB
#include<bits/stdc++.h>
#define qc ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rt return
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vecin(a) for(auto &d:a)cin>>d;
typedef long long int ll;
const long long mod=1e9+7;
const int int_inf=2147483647;
const long long int ll_inf=9223372036854775807;
const int alp_up=64;
const int alp_lw=96;
int dx[]={-1,-1,0,1,1,1,0,-1};
int dy[]={0,1,1,1,0,-1,-1,-1};
using namespace std;
ll gcd(ll a,ll b){if(b==0)rt a;rt gcd(b,a%b);}
ll lcm(ll a,ll b){rt a/gcd(a,b)*b;}
void setIO(string name)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}

//*
int n;
vector<int>l,r;
void init(int N,vector<int>h)
{
    n=N;
    l.resize(n,-1);
    r.resize(n,-1);
    stack<int>s;
    for(int i=0;i<n;i++)
    {
        while(!s.empty()&&h[s.top()]<h[i])s.pop();
        if(!s.empty())l[i]=s.top();
        s.push(i);
    }
    for(int i=n-1;i>=0;i--)
    {
        while(h[s.top()]<h[i])s.pop();
        if(!s.empty())r[i]=s.top();
        s.push(i);
    }
    //for(auto c:l)cout<<c<<" ";cout<<"\n";
    //for(auto c:r)cout<<c<<" ";cout<<"\n";
}
int minimum_jumps(int a,int b,int c,int d)
{
    queue<pair<int,int>>q;
    vector<bool>vis(n,0);
    for(int i=a;i<=b;i++){
        q.push({i,0});
    }
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        //cout<<x<<" ";
        if(c<=x&&x<=d)rt y;
        if(l[x]!=-1&&!vis[l[x]]){
            q.push({l[x],y+1});
            vis[l[x]]=1;
        }
        if(r[x]!=-1&&!vis[r[x]]){
            q.push({r[x],y+1});
            vis[r[x]]=1;
        }
    }
    rt -1;
}

int xmain()
{
    init(7, {3, 2, 1, 6, 4, 5, 7});
    cout<<minimum_jumps(4, 4, 6, 6)<<" "<<minimum_jumps(1, 3, 5, 6)<<" "<<minimum_jumps(0, 1, 2, 2);
    rt 0;
}
/*/

int n,k;
vector<pair<ll,int>>age;
vector<vector<pair<int,ll>>>edge;
vector<ll>ans;
//vector<bool>vis;
bool comp(pair<ll,int>a,pair<ll,int>b){rt a.se<b.se;}
int main()
{
    cin>>n>>k;
    age.resize(n);
    edge.resize(n);
    //vis.resize(n,0);
    ans.resize(n,ll_inf);
    for(int i=0;i<n;i++){
        cin>>age[i].first;
        age[i].second=i;
    }
    for(int i=0;i<k;i++){
        int u,v;cin>>u>>v;
        u--;v--;
        edge[u].push_back({v,0});
        edge[v].push_back({u,0});
    }
    sort(all(age));
    for(int i=0;i<n-1;i++){
        edge[age[i].second].push_back({age[i+1].second,abs(age[i].first-age[i+1].first)});
        edge[age[i+1].second].push_back({age[i].second,abs(age[i].first-age[i+1].first)});
    }
    ans[0]=0;
    priority_queue<pair<ll,int>>q;
    q.push({-ans[0],0});
    while(!q.empty()){
        int u=-q.top().first,v=q.top().second;
        q.pop();
        //if(vis[v])continue;
        //vis[v]=1;
        for(auto c:edge[v]){
            if(ans[c.fi]>ans[v]+c.se){
                ans[c.fi]=ans[v]+c.se;
                q.push({-ans[c.fi],c.fi});
            }
        }
    }


    for(auto c:ans)cout<<c<<" ";
}

//*/

Compilation message

jumps.cpp: In function 'void setIO(std::string)':
jumps.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen((name+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((name+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Execution timed out 4059 ms 3464 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 0 ms 208 KB Output is correct
27 Correct 2 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 2 ms 208 KB Output is correct
30 Correct 3 ms 208 KB Output is correct
31 Correct 3 ms 208 KB Output is correct
32 Correct 3 ms 208 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 0 ms 208 KB Output is correct
37 Correct 0 ms 208 KB Output is correct
38 Correct 1 ms 208 KB Output is correct
39 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 0 ms 208 KB Output is correct
27 Correct 2 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 2 ms 208 KB Output is correct
30 Correct 3 ms 208 KB Output is correct
31 Correct 3 ms 208 KB Output is correct
32 Correct 3 ms 208 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 0 ms 208 KB Output is correct
37 Correct 0 ms 208 KB Output is correct
38 Correct 1 ms 208 KB Output is correct
39 Correct 1 ms 208 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 0 ms 208 KB Output is correct
42 Correct 0 ms 208 KB Output is correct
43 Correct 0 ms 208 KB Output is correct
44 Correct 1 ms 208 KB Output is correct
45 Correct 3 ms 208 KB Output is correct
46 Correct 2 ms 208 KB Output is correct
47 Correct 3 ms 208 KB Output is correct
48 Correct 1 ms 208 KB Output is correct
49 Correct 3 ms 208 KB Output is correct
50 Correct 5 ms 208 KB Output is correct
51 Correct 3 ms 208 KB Output is correct
52 Correct 3 ms 208 KB Output is correct
53 Correct 3 ms 208 KB Output is correct
54 Correct 4 ms 208 KB Output is correct
55 Correct 3 ms 208 KB Output is correct
56 Correct 3 ms 208 KB Output is correct
57 Correct 0 ms 208 KB Output is correct
58 Correct 33 ms 208 KB Output is correct
59 Correct 65 ms 336 KB Output is correct
60 Correct 9 ms 308 KB Output is correct
61 Correct 49 ms 336 KB Output is correct
62 Correct 12 ms 208 KB Output is correct
63 Correct 46 ms 208 KB Output is correct
64 Correct 58 ms 336 KB Output is correct
65 Correct 67 ms 336 KB Output is correct
66 Correct 56 ms 336 KB Output is correct
67 Correct 42 ms 336 KB Output is correct
68 Correct 55 ms 336 KB Output is correct
69 Correct 41 ms 336 KB Output is correct
70 Correct 30 ms 336 KB Output is correct
71 Correct 0 ms 208 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 4 ms 208 KB Output is correct
74 Correct 3 ms 208 KB Output is correct
75 Correct 3 ms 208 KB Output is correct
76 Correct 3 ms 208 KB Output is correct
77 Correct 3 ms 208 KB Output is correct
78 Correct 0 ms 208 KB Output is correct
79 Correct 1 ms 208 KB Output is correct
80 Correct 2 ms 208 KB Output is correct
81 Correct 2 ms 208 KB Output is correct
82 Correct 2 ms 208 KB Output is correct
83 Correct 2 ms 208 KB Output is correct
84 Correct 2 ms 208 KB Output is correct
85 Correct 3 ms 208 KB Output is correct
86 Correct 0 ms 208 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 1 ms 208 KB Output is correct
89 Correct 1 ms 208 KB Output is correct
90 Correct 1 ms 208 KB Output is correct
91 Correct 1 ms 208 KB Output is correct
92 Correct 1 ms 208 KB Output is correct
93 Correct 0 ms 208 KB Output is correct
94 Correct 4 ms 300 KB Output is correct
95 Correct 42 ms 336 KB Output is correct
96 Correct 54 ms 336 KB Output is correct
97 Correct 47 ms 336 KB Output is correct
98 Correct 62 ms 336 KB Output is correct
99 Correct 57 ms 336 KB Output is correct
100 Correct 0 ms 208 KB Output is correct
101 Correct 1 ms 208 KB Output is correct
102 Correct 22 ms 208 KB Output is correct
103 Correct 35 ms 208 KB Output is correct
104 Correct 15 ms 208 KB Output is correct
105 Correct 46 ms 208 KB Output is correct
106 Correct 27 ms 208 KB Output is correct
107 Correct 0 ms 208 KB Output is correct
108 Correct 1 ms 208 KB Output is correct
109 Correct 1 ms 208 KB Output is correct
110 Correct 2 ms 208 KB Output is correct
111 Correct 1 ms 208 KB Output is correct
112 Correct 2 ms 208 KB Output is correct
113 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 25 ms 2852 KB Output is correct
6 Correct 31 ms 3360 KB Output is correct
7 Correct 13 ms 1864 KB Output is correct
8 Correct 42 ms 4252 KB Output is correct
9 Correct 6 ms 720 KB Output is correct
10 Correct 29 ms 3376 KB Output is correct
11 Correct 33 ms 4144 KB Output is correct
12 Correct 32 ms 3992 KB Output is correct
13 Correct 30 ms 3992 KB Output is correct
14 Correct 30 ms 3352 KB Output is correct
15 Correct 45 ms 3840 KB Output is correct
16 Correct 28 ms 4248 KB Output is correct
17 Correct 41 ms 4284 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
33 Correct 30 ms 3364 KB Output is correct
34 Correct 28 ms 3384 KB Output is correct
35 Correct 41 ms 3940 KB Output is correct
36 Correct 40 ms 3372 KB Output is correct
37 Correct 31 ms 3740 KB Output is correct
38 Correct 30 ms 4368 KB Output is correct
39 Correct 0 ms 208 KB Output is correct
40 Correct 21 ms 2016 KB Output is correct
41 Correct 28 ms 3356 KB Output is correct
42 Correct 41 ms 4012 KB Output is correct
43 Correct 24 ms 3372 KB Output is correct
44 Correct 29 ms 3728 KB Output is correct
45 Correct 36 ms 4144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 233 ms 1608 KB Output is correct
5 Correct 1035 ms 3424 KB Output is correct
6 Correct 483 ms 720 KB Output is correct
7 Correct 1084 ms 3352 KB Output is correct
8 Correct 621 ms 1392 KB Output is correct
9 Correct 992 ms 3372 KB Output is correct
10 Execution timed out 4058 ms 4148 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 233 ms 1608 KB Output is correct
5 Correct 1035 ms 3424 KB Output is correct
6 Correct 483 ms 720 KB Output is correct
7 Correct 1084 ms 3352 KB Output is correct
8 Correct 621 ms 1392 KB Output is correct
9 Correct 992 ms 3372 KB Output is correct
10 Execution timed out 4058 ms 4148 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Execution timed out 4059 ms 3464 KB Time limit exceeded
4 Halted 0 ms 0 KB -