# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935809 | 2024-02-29T14:35:01 Z | 8pete8 | Chorus (JOI23_chorus) | C++17 | 7000 ms | 221268 KB |
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<cassert> #include<limits.h> #include<cmath> #include<set> #include<numeric> //gcd(a,b) #include<algorithm> #include<bitset> #include<stack> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define pppiiii pair<pii,pii> #define ppii pair<int,pii> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define pb push_back //#define mp make_pair #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") #define int long long const int mod=1e9+7,mxn=5005,lg=30,inf=1e18,minf=-1e18,Mxn=2e6,root=700; void setIO(string name){ ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } int dp[mxn+10][mxn+10]; int cost[mxn+10][mxn+10]; int pref[mxn*2+10]; vector<int>A,B; int n,k; string a; void getcost(int st){ int curcost=0; for(int i=A[st];i<=n*2;i++){ if(a[i]=='A')pref[i]++; pref[i]+=pref[i-1]; } for(int i=st;i<=n;i++){ cost[st][i]=cost[st][i-1]+pref[B[i]]; } for(int i=A[st];i<=2*n;i++)pref[i]=0; /* when introduced new B */ } int32_t main(){ fastio cin>>n>>k; cin>>a; reverse(all(a)); a='G'+a; A.pb(69); B.pb(420); for(int i=1;i<=n*2;i++){ if(a[i]=='A')A.pb(i); else B.pb(i); } for(int i=1;i<=n;i++)getcost(i); for(int i=0;i<=k;i++)for(int j=1;j<=n;j++)dp[j][i]=inf; dp[0][0]=0; for(int i=1;i<=k;i++){//choose k use pref j for(int j=1;j<=n;j++){ for(int g=1;g<=j;g++){ dp[j][i]=min(dp[j][i],dp[g-1][i-1]+cost[g][j]); } } } cout<<dp[n][k]; //can op to (n^2logn)? dac dp? //too lazy to prove :(( }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4700 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 2 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4552 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4700 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 2 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4552 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 3 ms | 11356 KB | Output is correct |
18 | Correct | 21 ms | 27740 KB | Output is correct |
19 | Correct | 49 ms | 27740 KB | Output is correct |
20 | Correct | 7 ms | 27992 KB | Output is correct |
21 | Correct | 7 ms | 27740 KB | Output is correct |
22 | Correct | 87 ms | 27828 KB | Output is correct |
23 | Correct | 84 ms | 27828 KB | Output is correct |
24 | Correct | 8 ms | 27740 KB | Output is correct |
25 | Correct | 83 ms | 27816 KB | Output is correct |
26 | Correct | 71 ms | 27740 KB | Output is correct |
27 | Correct | 32 ms | 27992 KB | Output is correct |
28 | Correct | 32 ms | 27840 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4700 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 2 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4552 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 3 ms | 11356 KB | Output is correct |
18 | Correct | 21 ms | 27740 KB | Output is correct |
19 | Correct | 49 ms | 27740 KB | Output is correct |
20 | Correct | 7 ms | 27992 KB | Output is correct |
21 | Correct | 7 ms | 27740 KB | Output is correct |
22 | Correct | 87 ms | 27828 KB | Output is correct |
23 | Correct | 84 ms | 27828 KB | Output is correct |
24 | Correct | 8 ms | 27740 KB | Output is correct |
25 | Correct | 83 ms | 27816 KB | Output is correct |
26 | Correct | 71 ms | 27740 KB | Output is correct |
27 | Correct | 32 ms | 27992 KB | Output is correct |
28 | Correct | 32 ms | 27840 KB | Output is correct |
29 | Execution timed out | 7012 ms | 221268 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4700 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 2 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4552 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 3 ms | 11356 KB | Output is correct |
18 | Correct | 21 ms | 27740 KB | Output is correct |
19 | Correct | 49 ms | 27740 KB | Output is correct |
20 | Correct | 7 ms | 27992 KB | Output is correct |
21 | Correct | 7 ms | 27740 KB | Output is correct |
22 | Correct | 87 ms | 27828 KB | Output is correct |
23 | Correct | 84 ms | 27828 KB | Output is correct |
24 | Correct | 8 ms | 27740 KB | Output is correct |
25 | Correct | 83 ms | 27816 KB | Output is correct |
26 | Correct | 71 ms | 27740 KB | Output is correct |
27 | Correct | 32 ms | 27992 KB | Output is correct |
28 | Correct | 32 ms | 27840 KB | Output is correct |
29 | Execution timed out | 7012 ms | 221268 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 4440 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4700 KB | Output is correct |
9 | Correct | 1 ms | 4440 KB | Output is correct |
10 | Correct | 2 ms | 4444 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4552 KB | Output is correct |
15 | Correct | 1 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 3 ms | 11356 KB | Output is correct |
18 | Correct | 21 ms | 27740 KB | Output is correct |
19 | Correct | 49 ms | 27740 KB | Output is correct |
20 | Correct | 7 ms | 27992 KB | Output is correct |
21 | Correct | 7 ms | 27740 KB | Output is correct |
22 | Correct | 87 ms | 27828 KB | Output is correct |
23 | Correct | 84 ms | 27828 KB | Output is correct |
24 | Correct | 8 ms | 27740 KB | Output is correct |
25 | Correct | 83 ms | 27816 KB | Output is correct |
26 | Correct | 71 ms | 27740 KB | Output is correct |
27 | Correct | 32 ms | 27992 KB | Output is correct |
28 | Correct | 32 ms | 27840 KB | Output is correct |
29 | Execution timed out | 7012 ms | 221268 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |