Submission #537044

#TimeUsernameProblemLanguageResultExecution timeMemory
537044joelauPopeala (CEOI16_popeala)C++14
0 / 100
476 ms18920 KiB
#include <bits/stdc++.h> using namespace std; long long N,T,S, A[20005], B[55][20005], dp[2][20005], spt[55][20005][20], pos[55], inf = 2100000000; vector<long long> v; inline long long rd() { long long x = 0; char ch = getchar_unlocked(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } long long query (long long n, long long i, long long j) { long long k = (long long) floor(log((double)j-i+1) / log(2.0)); return min(spt[n][i][k],spt[n][j-(1<<k)+1][k]); } int main() { N = rd(), T = rd(), S = rd(); A[0] = 0; for (long long i = 1; i <= T; ++i) { A[i] = rd(); A[i] += A[i-1]; } for (long long i = 1; i <= N; ++i) for (long long j = 1; j <= T; ++j) { char ch = getchar_unlocked(); B[i][j] = ch - '0'; } for (long long i = 0; i <= T; ++i) dp[0][i] = dp[1][i] = inf; dp[1][0] = 0; for (long long a = 1; a <= S; ++a) { for (long long n = 0; n <= N; ++n) { for (long long i = 0; i <= T; ++i) spt[n][i][0] = dp[1][i] == inf ? inf : dp[1][i] - n * A[i]; for (long long j = 1; (1<<j) <= T+1; ++j) for (long long i = 0; i + (1<<j) - 1 <= T; ++i) spt[n][i][j] = min(spt[n][i][j-1],spt[n][i+(1<<(j-1))][j-1]); } dp[0][0] = inf; memset(pos,0,sizeof(pos)); for (long long i = 1; i <= T; ++i) { v.clear(); for (long long j = 1; j <= N; ++j) { if (B[j][i] == 0) pos[j] = i; v.push_back(pos[j]); } sort(v.begin(),v.end()); dp[0][i] = inf; if (v[0] != 0) dp[0][i] = query(0,0,v[0]-1); for (long long j = 1; j < N; ++j) if (v[j] != v[j-1] && query(j,v[j-1],v[j]-1) != inf) dp[0][i] = min(dp[0][i], query(j,v[j-1],v[j]-1) + j * A[i]); if (v[N-1] <= i-1 && query(N,v[N-1],i-1) != inf) dp[0][i] = min(dp[0][i],query(N,v[N-1],i-1) + N * A[i]); } printf("%lld\n", dp[0][T]); swap(dp[0],dp[1]); } 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...