//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<ll,int,hash<ll>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int INF = 1e9 + 7;
const int MAXN = 55;
const int MAXT = 2e4 + 5;
const double eps = 1e-9;
int a[MAXT], dp[2][MAXT], sm[MAXT];
char str[MAXT];
ll msk[MAXT], tmp;
int f(int l, int r) {
int ret = sm[r];
if (l) ret -= sm[l-1];
return ret;
}
void dfs(int i, int l, int r, int oL, int oR, int idx) {
if (l > r) return;
int m = (l+r) / 2, nx = oL, sm = 0;
dp[i][m] = INF;
ll cur = tmp;
for (int j = min(oR, m); j >= max(oL,idx); j--) {
cur &= msk[j];
int val = __builtin_popcountll(cur) * f(j,m);
if (j) val += dp[i^1][j-1];
if (val < dp[i][m]) {
dp[i][m] = val;
nx = j;
}
}
dfs(i, l, m-1, oL, oR, idx);
dfs(i, m+1, r, oL, oR, idx);
}
int main() {
int n, t, s;
scanf("%d %d %d", &n, &t, &s);
tmp = (1ll << (ll)n) - 1;
for (int i = 0; i < t; i++) {
ni(a[i]);
if (i) sm[i] = sm[i-1];
sm[i] += a[i];
}
for (int i = 0; i < n; i++) {
scanf("%s", str);
for (int j = 0; j < t; j++)
if (str[j] == '1')
msk[j] |= (1ll << (ll)i);
}
fill(dp[1], dp[1] + MAXT, INF);
for (int i = 0; i < s; i++) {
dfs(i&1, 0, t-1, 0, t-1, i);
printf("%d\n", dp[i&1][t-1]);
}
return 0;
}
Compilation message
popeala.cpp: In function 'void dfs(int, int, int, int, int, int)':
popeala.cpp:51:21: warning: variable 'nx' set but not used [-Wunused-but-set-variable]
int m = (l+r) / 2, nx = oL, sm = 0;
^~
popeala.cpp:51:30: warning: unused variable 'sm' [-Wunused-variable]
int m = (l+r) / 2, nx = oL, sm = 0;
^~
popeala.cpp: In function 'int main()':
popeala.cpp:69:7: 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:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
popeala.cpp:72:3: note: in expansion of macro 'ni'
ni(a[i]);
^~
popeala.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", str);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
504 KB |
Output is correct |
2 |
Correct |
35 ms |
504 KB |
Output is correct |
3 |
Correct |
35 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
684 ms |
508 KB |
Output is correct |
2 |
Correct |
1275 ms |
632 KB |
Output is correct |
3 |
Execution timed out |
2056 ms |
764 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
35 ms |
504 KB |
Output is correct |
4 |
Correct |
35 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
504 KB |
Output is correct |
6 |
Correct |
684 ms |
508 KB |
Output is correct |
7 |
Correct |
1275 ms |
632 KB |
Output is correct |
8 |
Execution timed out |
2056 ms |
764 KB |
Time limit exceeded |