# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
201337 | guangxuan | Bigger segments (IZhO19_segments) | C++14 | 1574 ms | 142052 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
pair<int,long long> dp[500009];
unordered_map<long long,pair<int,long long> >fw;
pair<int,long long> query(long long x){
pair<int,long long> ans = {-1,-1};
for(x++;x;x-=x&(-x)){
if(fw.find(x)==fw.end())continue;
ans = max(ans,fw[x]);
}
return ans;
}
void up(long long x,pair<int,long long> v ){
for(x++;x<1e15;x+=x&(-x)){
if(fw.find(x)==fw.end())fw[x] = v;
else fw[x] = max(fw[x],v);
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
rs[i+1]=rs[i]+a[i];
}
up(0,{0,0});
for(int i=1;i<=n;i++){
pair<int,long long> res = query(rs[i]);
dp[i] = {res.first,res.second - rs[i]};
dp[i].first++;
up(rs[i] - dp[i].second,{dp[i].first,rs[i]});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp[n].first);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |