Submission #2139091
Source Code Expand
#include <iostream> #include <queue> #include <map> #include <list> #include <vector> #include <string> #include <stack> #include <limits> #include <climits> #include <cassert> #include <fstream> #include <cstring> #include <cmath> #include <bitset> #include <iomanip> #include <algorithm> #include <functional> #include <cstdio> #include <ciso646> #include <set> #include <array> #include <unordered_map> #include <complex> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f #define PB push_back #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define SET(a,c) memset(a,c,sizeof a) #define CLR(a) memset(a,0,sizeof a) #define VS vector<string> #define VI vector<ll> #define DEBUG(x) cout<<#x<<": "<<x<<endl #define MIN(a,b) (a>b?b:a) #define MAX(a,b) (a>b?a:b) #define pi 2*acos(0.0) #define INFILE() freopen("in0.txt","r",stdin) #define OUTFILE()freopen("out0.txt","w",stdout) #define ll long long #define ull unsigned long long #define pii pair<ll,ll> #define pcc pair<char,char> #define pic pair<ll,char> #define pci pair<char,ll> #define eps 1e-14 #define FST first #define SEC second #define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15) namespace { struct input_returnner { ll N; input_returnner(ll N_ = 0) :N(N_) {} template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); } template<typename T> operator T() const { T res; cin >> res; return res; } template<typename T> T operator - (T right) { return T(input_returnner()) - right; } template<typename T> T operator + (T right) { return T(input_returnner()) + right; } template<typename T> T operator * (T right) { return T(input_returnner()) * right; } template<typename T> T operator / (T right) { return T(input_returnner()) / right; } template<typename T> T operator << (T right) { return T(input_returnner()) << right; } template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; } }; template<typename T> input_returnner in() { return in<T>(); } input_returnner in() { return input_returnner(); } input_returnner in(ll N) { return std::move(input_returnner(N)); } } const ll MOD = 1e9 + 7; void solve(); signed main() { SETUP; solve(); #ifdef _DEBUG system("pause"); #endif return 0; } int dp[302][302][301] = {}; // dp[l][r][x] : x個文字列を変更する権利を使用した時に, [l,r)間で最長となる回文 void solve() { string S; cin >> S; int K; cin >> K; REP(i, S.size()) REP(x,K+1){ dp[i][i + 1][x] = 1; } FOR(w, 2, S.size()+1) { FOR(l, 0, S.size() + 1 - w) { FOR(x, 0, K+1) { int r = l + w; // cout << S[l] << " " << S[r-1] << endl; if (S[l] == S[r-1]) { dp[l][r][x] = dp[l + 1][r - 1][x] + 2; } else { dp[l][r][x] = max(dp[l + 1][r][x], dp[l][r - 1][x]); if(x-1 >= 0) dp[l][r][x] = max(dp[l][r][x], dp[l + 1][r - 1][x - 1] + 2); } } } } int res = 0; REP(i, K+1) { res = max(res, dp[0][S.size()][i]); } cout << res << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Reversed LCS |
User | kurenaif |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 3324 Byte |
Status | AC |
Exec Time | 67 ms |
Memory | 106752 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 900 / 900 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 26 ms | 106752 KB |
02.txt | AC | 55 ms | 106752 KB |
03.txt | AC | 37 ms | 106752 KB |
04.txt | AC | 29 ms | 106752 KB |
05.txt | AC | 42 ms | 106752 KB |
06.txt | AC | 26 ms | 106752 KB |
07.txt | AC | 67 ms | 106752 KB |
08.txt | AC | 56 ms | 106752 KB |
09.txt | AC | 25 ms | 106752 KB |
10.txt | AC | 66 ms | 106752 KB |
11.txt | AC | 42 ms | 106752 KB |
12.txt | AC | 33 ms | 106752 KB |
13.txt | AC | 26 ms | 106752 KB |
14.txt | AC | 67 ms | 106752 KB |
15.txt | AC | 43 ms | 106752 KB |
16.txt | AC | 27 ms | 106752 KB |
17.txt | AC | 33 ms | 106752 KB |
18.txt | AC | 38 ms | 106752 KB |
19.txt | AC | 38 ms | 106752 KB |
20.txt | AC | 56 ms | 106752 KB |
21.txt | AC | 27 ms | 106752 KB |
22.txt | AC | 37 ms | 106752 KB |
23.txt | AC | 26 ms | 106752 KB |
24.txt | AC | 29 ms | 106752 KB |
25.txt | AC | 27 ms | 106752 KB |
26.txt | AC | 26 ms | 106752 KB |
27.txt | AC | 26 ms | 106752 KB |
28.txt | AC | 38 ms | 106752 KB |
29.txt | AC | 26 ms | 106752 KB |
30.txt | AC | 27 ms | 106752 KB |
31.txt | AC | 26 ms | 106752 KB |
32.txt | AC | 26 ms | 106752 KB |
33.txt | AC | 25 ms | 106752 KB |
34.txt | AC | 26 ms | 106752 KB |
35.txt | AC | 26 ms | 106752 KB |
36.txt | AC | 43 ms | 106752 KB |
37.txt | AC | 26 ms | 106752 KB |
38.txt | AC | 67 ms | 106752 KB |
39.txt | AC | 26 ms | 106752 KB |
40.txt | AC | 43 ms | 106752 KB |
41.txt | AC | 1 ms | 256 KB |
42.txt | AC | 1 ms | 256 KB |
43.txt | AC | 45 ms | 106752 KB |
44.txt | AC | 1 ms | 256 KB |
45.txt | AC | 1 ms | 256 KB |
46.txt | AC | 1 ms | 256 KB |
47.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 2304 KB |
s2.txt | AC | 2 ms | 6528 KB |