# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
935807 | 2024-02-29T14:33:45 Z | 8pete8 | Chorus (JOI23_chorus) | C++17 | 8 ms | 604 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; int 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? idk :( //too lazy to prove :(( }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |