답안 #939137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939137 2024-03-06T06:10:44 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
1 ms 348 KB
#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

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++){
      |                   ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -