Submission #709955

# Submission time Handle Problem Language Result Execution time Memory
709955 2023-03-15T01:29:41 Z nicky4321 Group Photo (JOI21_ho_t3) C++14
44 / 100
5000 ms 5972 KB
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
const int MAX = 5007, MOD = 1e9 + 7;
ll a[MAX], bit[MAX], dp[MAX][MAX], ans[MAX];
 
void upd(int x, int v){
    while(x < MAX){
        bit[x] += v;
        x += x & -x;
    }
}
 
int qry(int x){
    int res = 0;
    while(x){
        res += bit[x];
        x -= x & -x;
    }
    return res;
}
 
void solve(){
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        ans[i] = 2e18;
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= i;j++){
            for(int k = n;k >= 1;k--){
                if(i < a[k]){
                    dp[j][i] += qry(n);
                }else if(j <= a[k] && a[k] <= i){
                    int pos = i - a[k] + j + 1;
                    dp[j][i] += qry(pos - 1);
                    upd(pos, 1);
                }
            }
            for(int k = 1;k <= n;k++){
                if(j <= a[k] && a[k] <= i){
                    int pos = i - a[k] + j + 1;
                    upd(pos, -1);
                }
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 1;j <= n;j++)
            ans[j] = min(ans[j], ans[i] + dp[i + 1][j]);
    }
    cout << ans[n] << '\n';
}
 
int main(){
    IOS
	// CASE
	    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 91 ms 1196 KB Output is correct
22 Correct 89 ms 1224 KB Output is correct
23 Correct 81 ms 1232 KB Output is correct
24 Correct 78 ms 1300 KB Output is correct
25 Correct 87 ms 1276 KB Output is correct
26 Correct 81 ms 1276 KB Output is correct
27 Correct 82 ms 1224 KB Output is correct
28 Correct 80 ms 1192 KB Output is correct
29 Correct 79 ms 1228 KB Output is correct
30 Correct 82 ms 1240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 91 ms 1196 KB Output is correct
22 Correct 89 ms 1224 KB Output is correct
23 Correct 81 ms 1232 KB Output is correct
24 Correct 78 ms 1300 KB Output is correct
25 Correct 87 ms 1276 KB Output is correct
26 Correct 81 ms 1276 KB Output is correct
27 Correct 82 ms 1224 KB Output is correct
28 Correct 80 ms 1192 KB Output is correct
29 Correct 79 ms 1228 KB Output is correct
30 Correct 82 ms 1240 KB Output is correct
31 Execution timed out 5018 ms 5972 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 91 ms 1196 KB Output is correct
22 Correct 89 ms 1224 KB Output is correct
23 Correct 81 ms 1232 KB Output is correct
24 Correct 78 ms 1300 KB Output is correct
25 Correct 87 ms 1276 KB Output is correct
26 Correct 81 ms 1276 KB Output is correct
27 Correct 82 ms 1224 KB Output is correct
28 Correct 80 ms 1192 KB Output is correct
29 Correct 79 ms 1228 KB Output is correct
30 Correct 82 ms 1240 KB Output is correct
31 Execution timed out 5018 ms 5972 KB Time limit exceeded
32 Halted 0 ms 0 KB -