Submission #1045014

#TimeUsernameProblemLanguageResultExecution timeMemory
1045014vjudge1Pastiri (COI20_pastiri)C++17
0 / 100
197 ms42676 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define OYY LLONG_MAX #define mod 998244353 #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define FOR for(int i=1;i<=n;i++) #define mid (start+end)/2 #define lim 500005 #define fi first #define se second vector<int> v[lim]; int n,k; int dp[lim][2]; int dizi[lim]; int yol[lim]; inline int f(int sira,int kim){ //cout<<sira<<" "<<kim<<endl; if(sira>=k+1)return 0; if(~dp[sira][kim])return dp[sira][kim]; int cev=LLONG_MAX; if(cev>f(sira+1,1)+1){ cev=f(sira+1,1)+1; yol[sira]=1; } int tut=dizi[sira]+dizi[sira+1],ek=1; if(tut&1)ek++; if(sira<=k-1){ if(cev>f(sira+2,0)+ek){ cev=f(sira+2,0)+ek; yol[sira]=2; } } return dp[sira][kim]=cev; } int32_t main(){ faster memset(dp,-1,sizeof(dp)); cin>>n>>k; FOR{ if(i==1)continue; int a,b;cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } for(int i=1;i<=k;i++){ cin>>dizi[i]; } cout<<f(1,1)<<endl; /* for(int i=1;i<=k;i++){ cout<<yol[i]<<" "; } cout<<endl;*/ set<int> st; int tut=1; while(tut<k){ //cout<<tut<<" "<<" "<<yol[tut]<<" "<<st.size()<<endl; /*for(auto x:st)cout<<x<<" "; cout<<endl;*/ if(yol[tut]==1){ st.insert(tut); tut++; } else{ int gec=dizi[tut+1]+dizi[tut]; if(gec&1){ st.insert(gec/2); st.insert(gec/2+1); } else{ st.insert(gec/2); } tut+=2; } } for(auto x:st){ cout<<x<<" "; } cout<<'\n'; 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...