Submission #1066404

#TimeUsernameProblemLanguageResultExecution timeMemory
1066404Dennis_JasonCat Exercise (JOI23_ho_t4)C++14
0 / 100
2 ms5032 KiB
#include <bitset> #include <cmath> #include <functional> #include <algorithm> #include <numeric> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <unordered_map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <cstring> #include <climits> #define pb push_back #define MOD 1000000007 #define NMAX 200001 #define nl '\n' #define INF 1000000007 #define pii1 pair<int, pair<int,int>> (1,(1,2)); #define pii pair<int,int> #define tpl tuple<int,int,int,int,int> using namespace std; ifstream fin("data.in"); ofstream fout("data.out"); /* ====================DEMONSTRATION====================== n=2 1....#####..## ....########## ####.......... ##########.... ##########.... 1....####....# =========================END=========================== */ int n; vector<int>v; vector<vector<int>>G(NMAX); int start; bool vis_s[NMAX],vis_d[NMAX]; int maxi[NMAX]; signed main() { cin>>n; v.resize(n+1); map<int,int>mp; for(int i=1;i<=n;++i) { cin >> v[i]; if (v[i] == n) start = i; mp[v[i]]=i; } for(int i=1;i<n;++i) { int x,y; cin>>x>>y; G[x].pb(y); G[y].pb(x); } for (int i = 1; i < start; ++i) vis_s[i] = 1; for(int i=start+1;i<=n;++i) vis_d[i]=1; int i=start; int ans_s=0; while(!(v[i-1]>v[i] && v[i]<v[i+1]) && i>0) { int aux=v[i]; vis_s[mp[aux]]=1; while(vis_s[mp[aux]]) aux--; // cout<<i<<" "<<aux<<" "<<abs(i-mp[aux])<<nl; ans_s+=abs(i-mp[aux]); i=mp[aux]; } int ans=0; i=start; int ans_d=0; while(!(v[i-1]>v[i] && v[i]<v[i+1]) && i>0) { int aux=v[i]; vis_d[mp[aux]]=1; while(vis_d[mp[aux]]) aux--; // cout<<i<<" "<<aux<<" "<<abs(i-mp[aux])<<nl; ans_d+=abs(i-mp[aux]); i=mp[aux]; } int ans_mid=0; while(!(v[i-1]>v[i] && v[i]<v[i+1]) && i>0) { int aux=v[i]; ans_mid+=(abs(i-mp[aux-1])); i=mp[aux-1]; } ans=max({ans_s,ans_d,ans_mid}); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...