Submission #619577

#TimeUsernameProblemLanguageResultExecution timeMemory
619577drdilyorPopeala (CEOI16_popeala)C++17
26 / 100
2067 ms8852 KiB
#include <bits/stdc++.h> #ifdef ONPC #define cerr cout #include "t_debug.cpp" #else #define debug(...) 42 #endif #define sz(a) ((int)(a).size()) using namespace std; using ll = long long; const int INF = 2e9+1; const ll INFL = 1e18; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; } const int N = 2e4, LOGN = 17, K = 64, MOD = 1e9+7; int solve() { int n, t, s; cin >> n >> t >> s; if (!cin) return 1; vector<int> pts(t); for (auto& i : pts) {cin >> i;} vector<int> ptsP(t+1); for (int i = 0; i < t; i++) { ptsP[i+1] =ptsP[i] + pts[i]; } vector<string> table(n); for (auto& i : table) {cin >> i;} vector<vector<int>> prev(n, vector<int>(t,-1)); for (int c = 0; c < n; c++) for (int tc = 0;tc < t; tc++) if (table[c][tc] == '0') prev[c][tc] = tc; else if (tc) prev[c][tc] = prev[c][tc-1]; int dp[t][s+1]; for (int i = 0; i < t; i++) { int count = 0; for (int c = 0; c < n; c++) { if (prev[c][i] == -1) count++; } dp[i][1] = ptsP[i+1] * count; for (int g = 2; g <= s; g++) { dp[i][g] = INF; vector<int> js(n); for (int k = 0; k < n; k++) { js[k] = prev[k][i]; } sort(js.begin(), js.end(), greater<>{}); for (int jj = 0; jj < n; jj++) { int j = js[jj]; if (j <= 0) break; int score = ptsP[i+1] - ptsP[j]; ll cur = score * (n - jj - 1)+ dp[j-1][g-1]; dp[i][g] = (int)min((ll)dp[i][g], cur); if (j == i) continue; cur = (ll)(ptsP[i+1] - ptsP[j+1]) * (n - jj) + dp[j][g-1]; dp[i][g] = (int)min((ll)dp[i][g], cur); } } } vector<bitset<K>> res(t); for (int tc = 0; tc < t; tc++) { for (int c = 0; c < n; c++) { res[tc][c] = table[c][tc] == '0'; } } int dp2[N+1][K+1]; dp2[t][0] = 0; for (int i = 0; i < t; i++) dp2[i][0] = INF; for (int g = 1; g <= s; g++) dp2[t][g] = INF; for (int i = t-1; i >= 0; i--) { for (int g = 1; g <= s; g++) { int score = 0; bitset<K> solved; dp2[i][g] = INF; for (int j = i; j < t; j++) { score += pts[j]; solved |= res[j]; int count = n -solved.count(); dp2[i][g] = min(dp2[i][g], score * count + dp2[j+1][g-1]); } } } for (int k = 1; k <= s; k++) { //cout << dp[t-1][k] << ' ' << dp2[0][k] << '\n'; cout << dp2[0][k] << '\n'; } return 0; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; #ifdef ONPC t = 10000; #endif while (t-- && cin) { if (solve()) break; #ifdef ONPC cout << "____________________" << endl; #endif } 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...