Submission #939137

#TimeUsernameProblemLanguageResultExecution timeMemory
939137vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) a.begin(), a.end() #define int long long /* 4 bonobo deleted racecar racecars */ void solve(){ string s; cin >> s; int n = s.size(); deque<char> dq; for(int i = 0;i < n; i++) dq.push_back(s[i]); int ans = 0; while(true){ int left = dq.size()-1; int idx = -1, suf = 1; int len = -1; for(int j = dq.size() - 1; j >= 0; j--, left--, suf++){ if(suf > left) break; int ok = 1; for(int i = 0; i + j < dq.size(); i++){ if(dq[i] != dq[i+j]){ ok = 0; break; } } if(ok){ len = suf; idx = j; } } if(idx == -1){ ans++; break; } while(len--){ dq.pop_back(); dq.pop_front(); } ans+= 2; if(dq.empty()) break; } cout << ans; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt; cin >> tt; while(tt--){ solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

palindromic.cpp: In function 'void solve()':
palindromic.cpp:27:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for(int i = 0; i + j < dq.size(); i++){
      |                   ~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...