Submission #729476

#TimeUsernameProblemLanguageResultExecution timeMemory
729476WKYHPermutation (APIO22_perm)C++17
10 / 100
604 ms51168 KiB
#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 main() { 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; } /*/ vector<int> construct_permutation(ll k) { k-=2; vector<int>ans; for(int i=k;i>=0;i--){ ans.push_back(i); } rt ans; } int smain() { } //*/

Compilation message (stderr)

perm.cpp: In function 'int smain()':
perm.cpp:96:1: warning: no return statement in function returning non-void [-Wreturn-type]
   96 | }
      | ^
perm.cpp: In function 'void setIO(std::string)':
perm.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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
perm.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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...