제출 #701873

#제출 시각아이디문제언어결과실행 시간메모리
701873sudheerays123수열 (APIO14_sequence)C++17
50 / 100
407 ms24732 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long int const ll N = 1000+5 , INF = 1e18 , MOD = 1e9+7; ll dp[N][N],par[N][N]; vector<ll> a(N),presum(N); ll n,k; ll go(ll i , ll j){ if(i == n+1){ if(j == k+1) return 0; return -INF; } if(j > k) return -INF; if(dp[i][j] != -1) return dp[i][j]; ll ans = -INF , ind; for(ll k = i; k <= n; k++){ if((presum[k]-presum[i-1])*(presum[n]-presum[k]) + go(k+1,j+1) > ans){ ans = (presum[k]-presum[i-1])*(presum[n]-presum[k]) + go(k+1,j+1); ind = k; } } par[i][j] = ind; return dp[i][j] = ans; } void solve(){ cin >> n >> k; for(ll i = 1; i <= n; i++){ cin >> a[i]; presum[i] = presum[i-1]+a[i]; } memset(dp,-1,sizeof dp); cout << go(1,0) << "\n"; ll curind = 1 , curk = 0; while(true){ if(curk == k) break; curind = par[curind][curk]; cout << curind << " "; curk++; curind++; } } int main(){ fast; ll tc = 1; // cin >> tc; while(tc--) solve(); return 0; }

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

sequence.cpp: In function 'long long int go(long long int, long long int)':
sequence.cpp:30:12: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |  par[i][j] = ind;
      |  ~~~~~~~~~~^~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...