답안 #175802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
175802 2020-01-07T11:16:33 Z 43V3R Bigger segments (IZhO19_segments) C++14
0 / 100
2 ms 376 KB
	#include <bits/stdc++.h>
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;

ll v[MAXN];

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    ll n;
    cin >> n;

    vector <ll> a(n + 1), pref(n + 1);
    vector <pll> dp(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }

    dp[0] = {0, 0};
    ll uk = 0;

    ll mx = 0;

    for(int i = 1; i <= n; i++){
        mx = max(mx, v[i]);
        dp[i] = {pref[i] - pref[mx], dp[mx].se + 1};

            ll l = i + 1, r = n;
            while(l < r){
                ll c = (l + r) >> 1;
                if(pref[c] - pref[i] < dp[i].fi)l = c + 1; else r = c;
            }
           // cout<<l;
            v[l] = max(v[l], ll(i));

    }

    cout << dp[n].se;

    return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:37:8: warning: unused variable 'uk' [-Wunused-variable]
     ll uk = 0;
        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 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 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 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 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 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 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 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 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -