Submission #1106345

# Submission time Handle Problem Language Result Execution time Memory
1106345 2024-10-30T03:18:29 Z _callmelucian Palinilap (COI16_palinilap) C++14
17 / 100
1000 ms 592 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

bool palin (const string &s) {
    return equal(all(s), s.rbegin());
}

int cost (const string &s) {
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
        for (int j = 1; j <= (int)s.size() - i; j++) ans += palin(s.substr(i, j));
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    string s; cin >> s;
    int n = s.length();

    int ans = 0;
    for (int i = 0; i < n; i++) {
        char c = s[i];
        for (int j = 0; j < 26; j++) {
            s[i] = char('a' + j);
            ans = max(ans, cost(s));

            //cout << "change " << i + 1 << " to " << char('a' + j) << " " << cost(s) << "\n";
        }
        s[i] = c;
    }
    cout << ans << "\n";

    return 0;
}

Compilation message

palinilap.cpp: In function 'int cost(const string&)':
palinilap.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 106 ms 336 KB Output is correct
2 Correct 359 ms 336 KB Output is correct
3 Correct 210 ms 336 KB Output is correct
4 Correct 206 ms 336 KB Output is correct
5 Correct 192 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 592 KB Time limit exceeded
2 Halted 0 ms 0 KB -