Submission #431697

#TimeUsernameProblemLanguageResultExecution timeMemory
431697sikamax2019Palindromes (APIO14_palindrome)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; int longestPalSubstr(string str) { int n = str.size(); bool table[n][n]; memset(table, 0, sizeof(table)); int maxLength = 1; for (int i = 0; i < n; ++i) table[i][i] = true; int start = 0; for (int i = 0; i < n - 1; ++i) { if (str[i] == str[i + 1]) { table[i][i + 1] = true; start = i; maxLength = 2; } } for (int k = 3; k <= n; ++k) { for (int i = 0; i < n - k + 1; ++i) { int j = i + k - 1; if (table[i + 1][j - 1] && str[i] == str[j]) { table[i][j] = true; if (k > maxLength) { start = i; maxLength = k; } } } } return maxLength; } int main() { freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout); string str; cin>>str; cout << longestPalSubstr(str); return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'int longestPalSubstr(std::string)':
palindrome.cpp:16:6: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   16 |  int start = 0;
      |      ^~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:45:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  freopen("palindrome.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:46:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  freopen("palindrome.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...