제출 #1163049

#제출 시각아이디문제언어결과실행 시간메모리
1163049SmuggingSpunBigger segments (IZhO19_segments)C++20
0 / 100
0 ms324 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
template<class T>void maximize(T& a, T b){
    if(a < b){
        a = b;
    }
}
int n;
namespace sub123{
    void solve(){
        vector<ll>f(n + 1);
        f[0] = 0;
        for(int i = 1; i <= n; i++){
            cin >> f[i];
            f[i] += f[i - 1];
        }
        vector<vector<int>>dp(n + 1, vector<int>(n + 1, 0));
        for(int l = dp[1][1] = 1; l < n; l++){
            for(int r = l; r < n; r++){
                maximize(dp[l][r + 1], dp[l][r]);
                int low = r + 1, high = n, p = -1;
                while(low <= high){
                    int mid = (low + high) >> 1;
                    if(f[mid] - f[r] >= f[r] - f[l - 1]){
                        high = (p = mid) - 1;
                    }
                    else{
                        low = mid + 1;
                    }
                }                
                if(p != -1){
                    maximize(dp[r + 1][p], dp[l][r] + 1);
                }
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            maximize(ans, dp[i][n]);
        }
        cout << ans;
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
    }
    cin >> n;
    if(n <= 3000){
        sub123::solve();
    }
}

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

segments.cpp: In function 'int main()':
segments.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(taskname".inp", "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...