제출 #645118

#제출 시각아이디문제언어결과실행 시간메모리
645118TimDeeSum Zero (RMI20_sumzero)C++17
0 / 100
32 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i,n) for (int i=0; i<n; ++i) void solve() { int n; cin>>n; if (n>=10000) { cout<<4; return; } vector<int> a(n); forn(i,n) cin>>a[i]; vector<vector<int>> dp(n+1,vector<int>(n+1,0)); vector<int> good(n,-1); forn(i,n) { int sum=0; for (int j=i; j<n; ++j) { sum+=a[j]; if (sum==0) { good[i]=j; break; } } } for (int i=1; i<=n; ++i) { for (int j=i; j<=n; ++j) { dp[i][j]=max(dp[i][j],dp[i][j-1]); if (good[j-1]==-1) continue; dp[i][good[j-1]+1]=max(dp[i][good[j-1]+1],dp[i][j-1]+1); } } int Q; cin>>Q; forn(q,Q) { int l,r; cin>>l>>r; cout<<dp[l][r]<<'\n'; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...