답안 #398247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398247 2021-05-04T02:19:27 Z fun_day Palindromic Partitions (CEOI17_palindromic) C++14
35 / 100
10000 ms 924 KB
#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << " - " << #x << ": " << x << '\n';
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << '\n';
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << " ,"; cerr << ']' << "\n";
string ss; 
int n ;
bool binary_s(int deb, int end , int len){
  string one = ss.substr(deb , len);
  string two = ss.substr(end-(len-1),len);
  return one == two;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while(tt--){
    cin >> ss; 
    n = ss.length();
    map<char , vector<int>> mp;
    for(int i = 0 ; i < n ; i++){
      mp[ss[i]].push_back(i);      
    }
    for(map<char, vector<int>>::iterator it = mp.begin();it!=mp.end() ; it++){
      reverse(it->second.begin(),it->second.end());  
    }
    int ans = 1;
    for(int i = n-1,qs = 0 ; qs < n/2 ; i--, qs++){
      map<int,bool>new_a;
      vector<int>test;
      for(int j = 0 ; j < (int)mp[ss[i]].size() ; j++){
        new_a[mp[ss[i]][j]-qs] = 1;
        test.push_back(mp[ss[i]][j]-qs);
      }
      vector<int>v = mp[ss[qs]];
      bool is = 1;
      for(int j = 0 ; j < (int)mp[ss[qs]].size() ; j++){
        if(v[j]<n/2 || v[j]>i)continue;
        if(new_a[i-v[j]]){
          if(binary_s(qs , i , i-v[j]+1)){
            int len = i-v[j];
            qs+=len;
            i-=len;
            ans += 2;
            is = 0;
            if(qs+1==i)ans--;
            break;
          }
        }
      }
      if(is)break;
    }
    cout << ans << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 460 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 18 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 460 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 18 ms 204 KB Output is correct
10 Execution timed out 10004 ms 924 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 460 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 18 ms 204 KB Output is correct
10 Execution timed out 10004 ms 924 KB Time limit exceeded
11 Halted 0 ms 0 KB -