제출 #1184262

#제출 시각아이디문제언어결과실행 시간메모리
1184262KhanhDangBigger segments (IZhO19_segments)C++20
37 / 100
8 ms328 KiB
#include<bits/stdc++.h>
using namespace std;
#define     ll long long
#define    pll pair<ll, ll>
#define    pii pair<int, int>
#define     fi first
#define     se second
#define all(v) (v).begin(), (v).end()
#define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end());
const int N = 3e3 + 5;
ll n, a[N], s[N];
pll dp[N];
ll get(int j, int i) {
    return s[i] - s[j - 1];
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "task"
    if (fopen(task".INP", "r")) {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    if (fopen("task.INP", "r")) {
        freopen("task.INP", "r", stdin);
        freopen("task.OUT", "w", stdout);
    }
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i], s[i] = s[i - 1] + a[i];
    //cout<<0<<' '<<0<<' '<<0<<'\n';
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            if (dp[j - 1].se <= get(j, i)) {
                if (dp[j - 1].fi + 1 > dp[i].fi)
                    dp[i] = {dp[j - 1].fi + 1, get(j, i)};
                else
                    dp[i].se = min(dp[i].se, get(j, i));
            }
        }
        //if (dp[i].se != dp[i - 1].se + a[i])
        //    cout<<i<<' '<<dp[i].fi<<' '<<dp[i].se<<'\n';
    }
    cout<<dp[n].fi;
    cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n";
}

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

segments.cpp: In function 'int main()':
segments.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("task.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...