Submission #536932

#TimeUsernameProblemLanguageResultExecution timeMemory
536932errorgornPopeala (CEOI16_popeala)C++17
26 / 100
2084 ms113868 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));(s)<(e)?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int k,n,s; int arr[20005]; int pre[20005]; string ac[51]; int memo[2][20005]; int ver[51][20005]; int pp[51]; struct node{ int table[15][20005]; void init(int v[20005]){ int n=k+1; rep(x,0,n) table[0][x]=v[x]; int layer=0; n--; while (n>0){ rep(x,0,n) table[layer+1][x]=min(table[layer][x],table[layer][x+(1<<layer)]); layer++; n-=1<<layer; } } int query(int i,int j){ int len=j-i+1; int layer=31-__builtin_clz(len); return min(table[layer][i],table[layer][j-(1<<layer)+1]); } } root[51]; signed main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n>>k>>s; rep(x,1,k+1) cin>>arr[x]; rep(x,1,k+1) pre[x]=pre[x-1]+arr[x]; rep(x,0,n) cin>>ac[x]; rep(x,0,n) ac[x]="$"+ac[x]; memset(memo,63,sizeof(memo)); int a=0,b=1; memo[a][0]=0; rep(zzz,0,s){ memset(memo[b],63,sizeof(memo[b])); rep(x,0,n+1){ rep(y,0,k+1) ver[x][y]=memo[a][y]-x*pre[y]; root[x].init(ver[x]); } rep(x,0,n) pp[x]=0; rep(x,1,k+1){ rep(y,0,n) if (ac[y][x]=='0') pp[y]=x; vector<int> imp={0,x}; rep(y,0,n) imp.pub(pp[y]); sort(all(imp)); reverse(all(imp)); //cout<<"debug: "; for (auto it:imp) cout<<it<<" "; cout<<endl; int best=1e18; int curr=0; rep(y,0,n+1){ if (imp[y]!=imp[y+1]){ //cout<<"debug2: "<<n-y<<" "<<imp[y+1]<<" "<<imp[y]-1<<endl; //cout<<root[n-y].query(imp[y+1],imp[y]-1)<<endl; best=min(best,root[n-y].query(imp[y+1],imp[y]-1)+curr); } curr-=pre[x]; } best+=n*pre[x]; memo[b][x]=best; } swap(a,b); //rep(x,0,k+1) cout<<memo[a][x]<<" "; cout<<endl; cout<<memo[a][k]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...