Submission #96509

#TimeUsernameProblemLanguageResultExecution timeMemory
96509jasony123123Popeala (CEOI16_popeala)C++11
100 / 100
369 ms14600 KiB
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; #define FOR(i,start,end) for(int i=start;i<(int)(end);i++) #define FORE(i,start,end) for(int i=start;i<=(int)end;i++) #define RFOR(i,start,end) for(int i = start; i>end; i--) #define RFORE(i,start,end) for(int i = start; i>=end; i--) #define all(a) a.begin(), a.end() #define mt make_tuple #define mp make_pair #define v vector #define sf scanf #define pf printf #define dvar(x) cout << #x << " := " << x << "\n" #define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n" typedef unsigned long long ll; typedef long double ld; typedef pair<int, int > pii; typedef pair<ll, ll> pll; //template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void minn(T &a, T b) { a = min(a, b); } template<class T> void maxx(T &a, T b) { a = max(a, b); } void io() { #ifdef LOCAL_PROJECT freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #else #endif ios_base::sync_with_stdio(false); cin.tie(NULL); } const ll INF = 1e14; /***********************CEOI 2016 D2 Popeala*****************************************/ const int MAXN = 50, MAXT = 20000; int N, T, S; ll P[MAXT]; int res[MAXN][MAXT]; ll dp[MAXN + 1][MAXT + 1]; int G[MAXT]; ll best[MAXN + 1]; int last[MAXN]; v<int> badIntv[MAXT]; int main() { io(); cin >> N >> T >> S; FOR(i, 0, T) cin >> P[i]; FOR(i, 0, N) FOR(j, 0, T) { char c; cin >> c; res[i][j] = c - '0'; } FORE(i, 0, S) FORE(j, 0, T) dp[i][j] = INF; dp[0][T] = 0; FOR(i, 0, N) last[i] = T; RFORE(i, T - 1, 0) { FOR(c, 0, N) if (res[c][i] == 0) { if (i + 1 < last[c]) badIntv[i].push_back(last[c] - 1); last[c] = i; } sort(all(badIntv[i])); } FORE(k, 1, S) { FORE(g, 0, N) best[g] = INF; RFORE(i, T - 1, 0) { FORE(g, 0, N) best[g] += g*P[i]; for (auto j : badIntv[i]) best[G[j]] = INF; if (!badIntv[i].empty()) { int pb = 0; // pointer to first j<badintv[i][pb] int sum = P[i]; FOR(j, i + 1, T) { G[j] -= badIntv[i].size() - pb; sum += P[j]; minn(best[G[j]], G[j] * sum + dp[k - 1][j + 1]); while (pb < badIntv[i].size() && badIntv[i][pb] <= j) pb++; if (pb == badIntv[i].size()) break; } } // add i into best int num1 = 0; FOR(c, 0, N) if (res[c][i] == 1) num1++; G[i] = num1; minn(best[num1], P[i] * num1 + dp[k - 1][i + 1]); // calc dp[k][i] FORE(g, 0, N) minn(dp[k][i], best[g]); //cout << "dp " << k << " " << i << " = " << dp[k][i] << "\n"; // //int temp[MAXT]; //memset(temp, 0, sizeof temp); //FOR(c, 0, N) { // for (int x = i; x < T && res[c][x] == 1; x++) // temp[x]++; //} //cout << "correct G\n"; //FOR(x, i, T) // cout << temp[x] << " "; //cout << "\n"; //cout << "my G\n"; //FOR(x, i, T) // cout << G[x] << " "; //cout << "\n"; //cout << "\n"; } } FORE(i, 1, S) cout << dp[i][0] << "\n"; }

Compilation message (stderr)

popeala.cpp: In function 'int main()':
popeala.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while (pb < badIntv[i].size() && badIntv[i][pb] <= j)
             ~~~^~~~~~~~~~~~~~~~~~~
popeala.cpp:95:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if (pb == badIntv[i].size())
          ~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...