//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;
inline int myrand(int l, int r) {
int ret = rand(); ret <<= 15; ret ^= rand();
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
return os<<"(" <<p.first<<", "<<p.second<<")"; }
typedef pair<int, int> ii;
template<typename T> using min_pq =
std::priority_queue<T, vector<T>, greater<T> >;
//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};
int n, t, s;
ll pre[20005];
ll dp[53][20005];
ll bit[20005];
int32_t main () {
// freopen("in", "r", stdin);
scanf("%d %d %d", &n, &t, &s);
for(int i = 1; i <= t; i++) {
scanf("%d", &pre[i]);
pre[i] += pre[i - 1];
}
char ss[10005];
for(int i = 0; i < n; i++) {
scanf("%s", ss);
for(int j = 0; j < t; j++) {
if(ss[j] - '0') bit[j + 1] |= (1LL << i);
}
}
for(int i = 1; i <= s; i++) dp[i][0] = ~2U >> 1;
for(int i = 1; i <= t; i++) dp[0][i] = ~2U >> 1;
for(int i = 1; i <= s; i++) {
for(int j = 1; j <= t; j++) {
dp[i][j] = 2e9;
ll cur = ~0;
for(int k = j; k >= 1; k--) {
cur &= bit[k];
dp[i][j] = min(dp[i][j], dp[i - 1][k - 1] + (pre[j] - pre[k - 1]) * __builtin_popcountll(cur));
}
}
}
for(int i = 1; i <= s; i++)
printf("%d\n", (int)dp[i][t]);
}
Compilation message
popeala.cpp: In function 'int myrand(int, int)':
popeala.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~
popeala.cpp:18:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~~
popeala.cpp: In function 'int32_t main()':
popeala.cpp:43:25: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll* {aka long long int*}' [-Wformat=]
scanf("%d", &pre[i]);
~~~~~~~^
popeala.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &t, &s);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:43:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &pre[i]);
~~~~~^~~~~~~~~~~~~~~
popeala.cpp:48:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", ss);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
808 KB |
Output is correct |
2 |
Correct |
43 ms |
1012 KB |
Output is correct |
3 |
Correct |
43 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
694 ms |
1716 KB |
Output is correct |
2 |
Correct |
1599 ms |
2084 KB |
Output is correct |
3 |
Execution timed out |
2059 ms |
2368 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
560 KB |
Output is correct |
3 |
Correct |
40 ms |
808 KB |
Output is correct |
4 |
Correct |
43 ms |
1012 KB |
Output is correct |
5 |
Correct |
43 ms |
1012 KB |
Output is correct |
6 |
Correct |
694 ms |
1716 KB |
Output is correct |
7 |
Correct |
1599 ms |
2084 KB |
Output is correct |
8 |
Execution timed out |
2059 ms |
2368 KB |
Time limit exceeded |