제출 #1041710

#제출 시각아이디문제언어결과실행 시간메모리
1041710abczzChorus (JOI23_chorus)C++17
16 / 100
93 ms21016 KiB
#include <iostream> #include <algorithm> #include <deque> #include <vector> #include <array> #define ll long long using namespace std; ll n, k, dp[5000][5000]; vector <ll> A, B, nxA, ps; string S; ll C(ll l, ll r) { if (nxA[l] > A[r]) return 0; ll nx = max(l, nxA[l]), cnt = r-nx+1, cnt2 = max(0LL, l-nxA[l]); return ps[r]-(nx ? ps[nx-1] : 0)-cnt*B[l]-cnt*(cnt-1)/2-(r-l+1)*cnt2; } int main() { cin >> n >> k >> S; for (int i=0; i<2*n; ++i) { if (S[i] == 'A') { ps.push_back((ps.empty() ? 0 : ps.back()) + i); A.push_back(i); } else { B.push_back(i); nxA.push_back(A.size()); } } for (int i=0; i<n; ++i) dp[i][0] = C(0, i); for (int x=1; x<k; ++x) { for (int i=0; i<n; ++i) { dp[i][x] = 1e18; ll optid = -1; for (int j=0; j<i; ++j) { if (dp[i][x] > dp[j][x-1] + C(j+1, i)) { dp[i][x] = dp[j][x-1] + C(j+1, i); optid = j; } } } } /*for (int x=0; x<k; ++x) { for (int i=0; i<n; ++i) { cout << dp[i][x] << " "; } cout << endl; }*/ cout << dp[n-1][k-1] << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

chorus.cpp: In function 'int main()':
chorus.cpp:36:10: warning: variable 'optid' set but not used [-Wunused-but-set-variable]
   36 |       ll optid = -1;
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...