답안 #122347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122347 2019-06-28T05:19:34 Z BThero Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
2 ms 384 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)1e6 + 5;

int dp[MAXN];

char s[MAXN];

int n, ans;

void solve() {
    scanf("%s", s + 1);    

    for (n = 1; s[n]; ++n); 

    --n;

    fill(dp, dp + n + 1, 0);

    for (int r = 1; r <= n; ++r) {
        for (int l = 1; l <= r; ++l) {
            bool ok = 1;

            int l2 = n - r + 1;
            int r2 = n - l + 1;

            for (int k = 0; k <= r - l; ++k) {
                ok &= (s[l + k] == s[l2 + k]);                
            }

            if (ok) {
                dp[r] = max(dp[r], dp[l - 1] + 1);
            }
        }
    }

    ans = 1;

    for (int i = 1; i * 2 <= n; ++i) {
        ans = max(ans, dp[i] * 2 + (i * 2 != n));        
    }

    printf("%d\n", ans);
}

int main() {
    int tt;
    scanf("%d", &tt);

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

palindromic.cpp: In function 'void solve()':
palindromic.cpp:47:17: warning: unused variable 'r2' [-Wunused-variable]
             int r2 = n - l + 1;
                 ^~
palindromic.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s + 1);    
     ~~~~~^~~~~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &tt);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -