제출 #571803

#제출 시각아이디문제언어결과실행 시간메모리
571803HuyBigger segments (IZhO19_segments)C++17
100 / 100
91 ms20828 KiB
#include<bits/stdc++.h>
#define int long long
#define pii pair<ll,ll>
#define fi first
#define se second

/// where is my spirit

using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)1e8;
const int maxN = (int)5e5 + 5;
const int mod = 1e9 + 7;
const ll infty = 1e18;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n;
int a[maxN];
int pt[maxN];
int dp[maxN];
int ast[maxN];

void Read()
{
   cin >> n;
   for(int i = 1;i <= n;i++)
   {
       cin >> a[i];
       ast[i] = ast[i-1] + a[i];
   }
   for(int i = 1;i <= n;i++)
   {
       pt[i] = max(pt[i],pt[i-1]);
       dp[i] = max(dp[i],dp[pt[i]] + 1);
       int k = lower_bound(ast + 1,ast + n + 1,2 * ast[i] - ast[pt[i]]) - ast;
       if(k > n) continue;
       pt[k] = max(pt[k],i);
   }
   cout << dp[n];
}

void Solve()
{

}

void Debug()
{
    //Main_sub();
    //Naive();
}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

/*
4 1
1 1 1 1
1 2
2 3
3 4
*/




컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'void InputFile()':
segments.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("test.out","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...