Submission #609949

#TimeUsernameProblemLanguageResultExecution timeMemory
609949chirathnirodhaPopeala (CEOI16_popeala)C++17
100 / 100
375 ms12724 KiB
//Coded by Chirath Nirodha #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define P push #define I insert typedef long long ll; typedef long double ld; typedef unsigned long long ull; const string abc="abcdefghijklmnopqrstuvwxyz"; const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; const ll mod=1e9+7; const ll inf=1000000000000; inline void io(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve(){ io(); ll n,t,s;cin>>n>>t>>s; ll p[t+1];p[0]=0; int last[t+1][n+1]; memset(last,0,sizeof(last)); for(int i=1;i<=t;i++){ cin>>p[i]; p[i]+=p[i-1]; } for(int i=1;i<=n;i++){ string str;cin>>str; for(int j=0;j<t;j++){ if(str[j]=='1')last[j+1][i]=last[j][i]; else last[j+1][i]=j+1; } } for(int i=1;i<=t;i++){ last[i][0]=i; sort(last[i],last[i]+n+1); } ll dp[t+1][s+1]; for(int i=0;i<=t;i++)for(int j=0;j<=s;j++)dp[i][j]=inf; dp[0][0]=0; ll best[n+1]; for(int i=1;i<=s;i++){ for(int j=0;j<=n;j++)best[j]=inf; for(int j=1;j<=t;j++){ for(ll k=0;k<=n;k++){ for(int l=last[j-1][k];l<last[j][k];l++) best[k] = min(best[k],dp[l][i-1]-p[l]*k); dp[j][i]=min(dp[j][i],best[k]+p[j]*k); } } cout<<dp[t][i]<<endl; } } int main(){ io(); solve(); //int t;cin>>t;for(int i=0;i<t;i++)solve(); 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...