Submission #1066390

#TimeUsernameProblemLanguageResultExecution timeMemory
1066390Dennis_JasonCat Exercise (JOI23_ho_t4)C++14
0 / 100
2 ms4956 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[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[i]=1; int i=start; int ans=0; while(!(v[i-1]>v[i] && v[i]<v[i+1]) && i>0) { int aux=v[i]; vis[mp[aux]]=1; while(vis[mp[aux]]) aux--; // cout<<i<<" "<<aux<<" "<<abs(i-mp[aux])<<nl; ans+=abs(i-mp[aux]); i=mp[aux]; } 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...