CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Kyselyt
Sender:kluopaja
Submission time:2020-10-18 20:49:42 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.50 s2, 3details
#30.56 s3details
#40.51 s3details
#50.51 s3details

Compiler report

input/code.cpp: In function 'int solve(std::__cxx11::string)':
input/code.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i+1 < s.size(); ++i) {
                  ~~~~^~~~~~~~~~
input/code.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 3; i <= s.size(); ++i) {
                  ~~^~~~~~~~~~~
input/code.cpp:22:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; i+j <= s.size(); ++j) {
                    ~~~~^~~~~~~~~~~
input/code.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i <= s.size(); ++i) {
                  ~~^~~~~~~~~~~

Code

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
// CCAAABBBAA
//
const int N_MAX = 101;
// length of the segment, start of the segment
int dp1[N_MAX][N_MAX];
int dp2[N_MAX];
int solve(string s) {
memset(dp1, 0, sizeof(dp1));
memset(dp2, 0, sizeof(dp2));
for(int i = 0; i+1 < s.size(); ++i) {
if(s[i] != s[i+1]) {
dp1[2][i] = 1;
}
}
// i is the length of the segment
for(int i = 3; i <= s.size(); ++i) {
// j is the start of the segment
for(int j = 0; i+j <= s.size(); ++j) {
if(dp1[i-2][j+1] && s[j] != s[j+i-1]) {
dp1[i][j] = 1;
}
else {
for(int k = 2; k+2 <= i; ++k) {
if(dp1[k][j] && dp1[i-k][j+k]) {
dp1[i][j] = 1;
break;
}
}
}
}
}
/*
for(int i = 0; i < s.size(); ++i) {
for(int j = 0; j <= s.size(); ++j) {
cout<<i<<' '<<j<<' '<<dp1[j][i]<<'\n';
}
}
*/
// dp2[i] == the amount of characters that can
// be removed from 0...i-1
for(int i = 1; i <= s.size(); ++i) {
dp2[i] = dp2[i-1];;
for(int j = 0; j + 2 <= i; ++j) {
if(dp1[i-j][j]) {
dp2[i] = max(dp2[i], dp2[j] + i-j);
}
}
}
return dp2[s.size()];
}
int main() {
int tt;
cin>>tt;
for(int xx = 0; xx < tt; ++xx) {
string s;
cin>>s;
int ans = solve(s);
cout<<ans<<endl;
}
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100 100
70 8 72 88 42 78 85 41 23 36 6...

correct output
99
0
922
2579
1892
...

user output
2
2
0
2
0
...
Truncated

Test 2

Group: 2, 3

Verdict:

input
200000 200000
98 99 29 92 29 81 100 52 89 80...

correct output
1497732
2810356
9532632
6655773
5403513
...

user output
2
2
0
2
2
...
Truncated

Test 3

Group: 3

Verdict:

input
200000 200000
818377786 934884634 816080381 ...

correct output
86877225712611
94684086875470
92703793485296
38149694892093
61948503092286
...

user output
2
8
8
8
8
...
Truncated

Test 4

Group: 3

Verdict:

input
200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
0
0
0
0
0
...

user output
2
0
0
0
0
...
Truncated

Test 5

Group: 3

Verdict:

input
200000 200000
200000 199999 199998 199997 19...

correct output
15920862903
3193483321
18874982071
4846348926
3970697055
...

user output
2
2
2
4
4
...
Truncated