답안 #173469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173469 2020-01-04T08:28:58 Z emil_physmath Bigger segments (IZhO19_segments) C++17
0 / 100
2 ms 376 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
typedef pair<int, llong> Dp;

template<typename T1, typename T2>
inline ostream& operator<<(ostream& str, const pair<T1, T2>& p)
{
    return str << "{" << p.first << ", " << p.second << "}";
}
inline const Dp& BestDp(const Dp& a, const Dp& b)
{
    if (a.first == b.first) return a.second < b.second ? a : b;
    return a.first > b.first ? a : b;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x: a)
        cin >> x;
    vector<llong> pref(n);
    for (int i = 0; i < n; ++i)
        pref[i] = a[i] + (i ? pref[i - 1] : 0);
    vector<pair<int, llong>> dp(n);
    for (int i = 0; i < n; ++i)
        dp[i] = {1, pref[i]};
    for (int i = 0; i < n; ++i)
    {
        int j = -1;
        int l = i + 1, r = n - 1;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (pref[m] - pref[i] >= dp[i].second)
            {
                j = m;
                r = m - 1;
            }
            else
                l = m + 1;
        }
        if (j != -1)
        {
            dp[j] = BestDp(dp[j], {dp[i].first + 1, pref[j] - pref[i]});
            // cerr << "i: " << i << "; " << "j: " << j << "\t" << dp[j] << endl;
        }
    }
    /*for (int i = 0; i < dp.size(); ++i)
        cerr << "dp[" << i << "] = " << dp[i] << endl;*/
    cout << max_element(dp.begin(), dp.end())->first << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -