Submission #399588

#TimeUsernameProblemLanguageResultExecution timeMemory
399588fedoseevtimofeyCigle (COI21_cigle)C++14
48 / 100
1086 ms139584 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> #include <bitset> #include <chrono> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin >> n; vector <int> d(n); for (int i = 0; i < n; ++i) cin >> d[i]; vector <ll> pref(n + 1); for (int i = 0; i < n; ++i) { pref[i + 1] = pref[i] + d[i]; } vector <vector <pair <int, int>>> go(n); for (int i = 0; i + 1 < n; ++i) { int r = 0; for (int l = 1; l <= i + 1; ++l) { while (r <= n - i - 1 && pref[i + 1] - pref[i + 1 - l] > pref[i + r + 1] - pref[i + 1]) ++r; if (pref[i + 1] - pref[i + 1 - l] == pref[i + r + 1] - pref[i + 1]) { go[i].push_back({l, r}); } } } vector <vector <int>> dp(n + 1, vector <int> (n + 1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { int uk = 0; for (int k = 1; k + i <= n; ++k) { while (uk < go[i - 1].size() && j > go[i - 1][uk].first && k > go[i - 1][uk].second) ++uk; dp[i + k][k] = max(dp[i + k][k], dp[i][j] + uk); } } } int ans = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { ans = max(ans, dp[i][j]); } } cout << ans << '\n'; }

Compilation message (stderr)

cigle.cpp: In function 'int main()':
cigle.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while (uk < go[i - 1].size() && j > go[i - 1][uk].first && k > go[i - 1][uk].second) ++uk;
      |                ~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...