# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
974330 |
2024-05-03T08:33:35 Z |
berr |
Group Photo (JOI21_ho_t3) |
C++17 |
|
5000 ms |
197288 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=5005;
int ar[N][N], br[N][N], dp[N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for(auto &i: a) cin >> i;
for(int i=1; i<=n; i++) dp[i]=1e9;
for(int i=0; i<n; i++){
for(int l=0; l<i; l++){
ar[a[i]][a[l]]++;
}
for(int l=n-1; l>=0; l--){
ar[a[i]][l]+=ar[a[i]][l+1];
}
}
for(int i=1; i<=n; i++){
int v=0;
for(int l=i-1; l>=0; l--){
int v=0;
for(int j=i; j>l; j--){
v+=ar[j][i+1];
v+=ar[j][l+1]-ar[j][j];
}
dp[i]=min(dp[i], dp[l]+v);
}
// cout<<"-----"<<dp[i]<<"\n";
}
cout<<dp[n];
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:28:13: warning: unused variable 'v' [-Wunused-variable]
28 | int v=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
464 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
464 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
8540 KB |
Output is correct |
22 |
Correct |
3 ms |
8796 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
8796 KB |
Output is correct |
28 |
Correct |
3 ms |
8972 KB |
Output is correct |
29 |
Correct |
3 ms |
8792 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
464 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
8540 KB |
Output is correct |
22 |
Correct |
3 ms |
8796 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
8796 KB |
Output is correct |
28 |
Correct |
3 ms |
8972 KB |
Output is correct |
29 |
Correct |
3 ms |
8792 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
160 ms |
31772 KB |
Output is correct |
32 |
Correct |
158 ms |
31648 KB |
Output is correct |
33 |
Correct |
159 ms |
31780 KB |
Output is correct |
34 |
Correct |
163 ms |
31580 KB |
Output is correct |
35 |
Correct |
166 ms |
31576 KB |
Output is correct |
36 |
Correct |
162 ms |
31788 KB |
Output is correct |
37 |
Correct |
201 ms |
31780 KB |
Output is correct |
38 |
Correct |
167 ms |
31836 KB |
Output is correct |
39 |
Correct |
158 ms |
31576 KB |
Output is correct |
40 |
Correct |
156 ms |
31784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
464 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
8540 KB |
Output is correct |
22 |
Correct |
3 ms |
8796 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8792 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
8796 KB |
Output is correct |
28 |
Correct |
3 ms |
8972 KB |
Output is correct |
29 |
Correct |
3 ms |
8792 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
160 ms |
31772 KB |
Output is correct |
32 |
Correct |
158 ms |
31648 KB |
Output is correct |
33 |
Correct |
159 ms |
31780 KB |
Output is correct |
34 |
Correct |
163 ms |
31580 KB |
Output is correct |
35 |
Correct |
166 ms |
31576 KB |
Output is correct |
36 |
Correct |
162 ms |
31788 KB |
Output is correct |
37 |
Correct |
201 ms |
31780 KB |
Output is correct |
38 |
Correct |
167 ms |
31836 KB |
Output is correct |
39 |
Correct |
158 ms |
31576 KB |
Output is correct |
40 |
Correct |
156 ms |
31784 KB |
Output is correct |
41 |
Execution timed out |
5008 ms |
197288 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |