답안 #168290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168290 2019-12-12T09:28:47 Z Nordway Bigger segments (IZhO19_segments) C++14
100 / 100
556 ms 45368 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=5e5+11;
const int M=1e6+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const double EPS=1e-9;

int a[N];
ll p[N];
int dp[N];
ll val[N];

struct node{
  int val;

};

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    p[i]=p[i-1]+a[i];
  }
  dp[0]=0;
  val[0]=0;
  set<pair<ll,int>>S;
  S.insert(mp(0,0));
  for(int i=1;i<=n;i++){
    int j=0;
    while(!S.empty()){
      pair<ll,int>q=*S.begin();
      if(q.x>p[i])break;
      S.erase(q);
      j=max(j,q.y);
    }
    dp[i]=dp[j]+1;
    val[i]=p[i]-p[j];
    S.insert(mp(val[j]+p[j],j));
    S.insert(mp(val[i]+p[i],i));
  }
  cout<<dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 372 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 372 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 5 ms 508 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 372 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 5 ms 508 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 100 ms 9316 KB Output is correct
47 Correct 77 ms 3804 KB Output is correct
48 Correct 89 ms 3716 KB Output is correct
49 Correct 91 ms 4216 KB Output is correct
50 Correct 89 ms 3704 KB Output is correct
51 Correct 101 ms 3832 KB Output is correct
52 Correct 51 ms 2040 KB Output is correct
53 Correct 32 ms 1272 KB Output is correct
54 Correct 54 ms 2932 KB Output is correct
55 Correct 101 ms 3676 KB Output is correct
56 Correct 58 ms 3164 KB Output is correct
57 Correct 76 ms 5752 KB Output is correct
58 Correct 73 ms 4856 KB Output is correct
59 Correct 69 ms 3448 KB Output is correct
60 Correct 70 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 372 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 5 ms 508 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 100 ms 9316 KB Output is correct
47 Correct 77 ms 3804 KB Output is correct
48 Correct 89 ms 3716 KB Output is correct
49 Correct 91 ms 4216 KB Output is correct
50 Correct 89 ms 3704 KB Output is correct
51 Correct 101 ms 3832 KB Output is correct
52 Correct 51 ms 2040 KB Output is correct
53 Correct 32 ms 1272 KB Output is correct
54 Correct 54 ms 2932 KB Output is correct
55 Correct 101 ms 3676 KB Output is correct
56 Correct 58 ms 3164 KB Output is correct
57 Correct 76 ms 5752 KB Output is correct
58 Correct 73 ms 4856 KB Output is correct
59 Correct 69 ms 3448 KB Output is correct
60 Correct 70 ms 3384 KB Output is correct
61 Correct 556 ms 45368 KB Output is correct
62 Correct 501 ms 29812 KB Output is correct
63 Correct 435 ms 20276 KB Output is correct
64 Correct 436 ms 16632 KB Output is correct
65 Correct 439 ms 16988 KB Output is correct
66 Correct 494 ms 17044 KB Output is correct
67 Correct 403 ms 13824 KB Output is correct
68 Correct 203 ms 7032 KB Output is correct
69 Correct 262 ms 13304 KB Output is correct
70 Correct 494 ms 17152 KB Output is correct
71 Correct 253 ms 14072 KB Output is correct
72 Correct 412 ms 27084 KB Output is correct
73 Correct 361 ms 19704 KB Output is correct
74 Correct 346 ms 15332 KB Output is correct
75 Correct 353 ms 15480 KB Output is correct