답안 #890551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890551 2023-12-21T13:06:19 Z zeta7532 Cigle (COI21_cigle) C++17
100 / 100
266 ms 98644 KB
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
 
int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<vector<ll>> dp(N,vector<ll>(N,0));
    rep(i,N-1){
        vector<ll> l;
        vector<ll> r;
        ll sum_l=0;
        ll sum_r=0;
        for(ll j=i;j>=0;j--){
            sum_l+=A[j];
            l.push_back(sum_l);
        }
        for(ll j=i+1;j<N;j++){
            sum_r+=A[j];
            r.push_back(sum_r);
        }
        vector<pair<ll,ll>> P;
        ll now_l=0;
        ll now_r=0;
        while(now_l+1<l.size()&&now_r+1<r.size()){
            if(l[now_l]<r[now_r]){
                now_l++;
                continue;
            }
            if(l[now_l]>r[now_r]){
                now_r++;
                continue;
            }
            if(l[now_l]==r[now_r]){
                P.push_back({now_l,now_r});
                now_l++;
                now_r++;
                continue;
            }
        }
        reverse(all(P));
        rep(j,P.size()) P[j].fi=i-1-P[j].fi,P[j].se=i+2+P[j].se;
        ll now_j=0;
        ll cum=0;
        rep(j,i){
            if(now_j==P.size()) break;
            cum=max(cum,dp[j][i]);
            if(j==P[now_j].fi){
                dp[i+1][P[now_j].se]=cum+P.size()-now_j;
                now_j++;
            }
        }
        rep(j,N-1){
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
        }
    }
    ll ans=0;
    rep(j,N) ans=max(ans,dp[j][N-1]);
    cout << ans << endl;
    return 0;
}

Compilation message

cigle.cpp: In function 'int main()':
cigle.cpp:36:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while(now_l+1<l.size()&&now_r+1<r.size()){
      |               ~~~~~~~^~~~~~~~~
cigle.cpp:36:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while(now_l+1<l.size()&&now_r+1<r.size()){
      |                                 ~~~~~~~^~~~~~~~~
cigle.cpp:10:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define rep(i,n) for(ll i=0;i<n;i++)
......
   53 |         rep(j,P.size()) P[j].fi=i-1-P[j].fi,P[j].se=i+2+P[j].se;
      |             ~~~~~~~~~~        
cigle.cpp:53:9: note: in expansion of macro 'rep'
   53 |         rep(j,P.size()) P[j].fi=i-1-P[j].fi,P[j].se=i+2+P[j].se;
      |         ^~~
cigle.cpp:57:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             if(now_j==P.size()) break;
      |                ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 4 ms 1372 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 2 ms 1448 KB Output is correct
11 Correct 2 ms 1368 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 4 ms 1372 KB Output is correct
24 Correct 2 ms 1368 KB Output is correct
25 Correct 2 ms 1372 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Correct 3 ms 1372 KB Output is correct
30 Correct 2 ms 1448 KB Output is correct
31 Correct 2 ms 1368 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 2 ms 1444 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 3 ms 1368 KB Output is correct
38 Correct 3 ms 1400 KB Output is correct
39 Correct 4 ms 1372 KB Output is correct
40 Correct 2 ms 1372 KB Output is correct
41 Correct 2 ms 1624 KB Output is correct
42 Correct 2 ms 1372 KB Output is correct
43 Correct 2 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 2 ms 1180 KB Output is correct
46 Correct 3 ms 1372 KB Output is correct
47 Correct 2 ms 1396 KB Output is correct
48 Correct 3 ms 1444 KB Output is correct
49 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 4 ms 1372 KB Output is correct
24 Correct 2 ms 1368 KB Output is correct
25 Correct 2 ms 1372 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Correct 3 ms 1372 KB Output is correct
30 Correct 2 ms 1448 KB Output is correct
31 Correct 2 ms 1368 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 2 ms 1444 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 3 ms 1368 KB Output is correct
38 Correct 3 ms 1400 KB Output is correct
39 Correct 4 ms 1372 KB Output is correct
40 Correct 2 ms 1372 KB Output is correct
41 Correct 2 ms 1624 KB Output is correct
42 Correct 2 ms 1372 KB Output is correct
43 Correct 2 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 2 ms 1180 KB Output is correct
46 Correct 3 ms 1372 KB Output is correct
47 Correct 2 ms 1396 KB Output is correct
48 Correct 3 ms 1444 KB Output is correct
49 Correct 2 ms 1372 KB Output is correct
50 Correct 211 ms 98576 KB Output is correct
51 Correct 216 ms 98552 KB Output is correct
52 Correct 236 ms 98544 KB Output is correct
53 Correct 208 ms 98572 KB Output is correct
54 Correct 213 ms 98568 KB Output is correct
55 Correct 237 ms 98572 KB Output is correct
56 Correct 258 ms 98556 KB Output is correct
57 Correct 266 ms 98388 KB Output is correct
58 Correct 259 ms 98312 KB Output is correct
59 Correct 263 ms 98568 KB Output is correct
60 Correct 191 ms 98548 KB Output is correct
61 Correct 216 ms 98564 KB Output is correct
62 Correct 236 ms 98560 KB Output is correct
63 Correct 215 ms 98384 KB Output is correct
64 Correct 233 ms 98556 KB Output is correct
65 Correct 211 ms 98556 KB Output is correct
66 Correct 236 ms 98620 KB Output is correct
67 Correct 202 ms 98396 KB Output is correct
68 Correct 234 ms 98560 KB Output is correct
69 Correct 207 ms 98392 KB Output is correct
70 Correct 207 ms 98548 KB Output is correct
71 Correct 210 ms 98644 KB Output is correct
72 Correct 235 ms 98388 KB Output is correct