답안 #398207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398207 2021-05-03T23:49:12 Z fun_day Palindromic Partitions (CEOI17_palindromic) C++14
60 / 100
10000 ms 12160 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";

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while(tt--){
    string ss ; 
    cin >> ss ; 
    int n = ss.length();
    map<char, vector<int>>mp;
    map<char , int>start;
    for(int i = 0 ; i < n; i++){
      mp[ss[i]].push_back(i);        
      start[i] = 0;
    }
    int ans = 1;
    for(int i = n-1,qs = 0 ; qs< n/2 ; i--,qs++){
      char q = ss[i];
      string acc;
      bool is = 1;
      int idx = qs;
      if(mp[q][start[q]]<qs)start[q] = lower_bound(mp[q].begin(),mp[q].end(),qs)-mp[q].begin();
      for(int j = start[q] ; j < (int)mp[q].size() ; j++){
        if(mp[q][j]>=n/2)break;
        acc += ss.substr(idx , mp[q][j]-idx+1);
        int rs = acc.length();
        idx = mp[q][j]+1;
        if((acc[0] != ss[i-rs+1]) || (acc[rs-1]!=ss[i])){
          start[q] = j+1;
          continue;  
        }
        if(ss.substr(i-rs+1 , rs) == acc){
          acc.clear();
          ans+=2;
          i-=rs;
          i++;
          qs = mp[q][j];
          if(qs+1==i)ans--;
          is = 0;
          break;  
        }
        start[q] = j+1;
      }
      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 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 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 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 9 ms 452 KB Output is correct
11 Correct 6 ms 460 KB Output is correct
12 Correct 7 ms 452 KB Output is correct
13 Correct 8 ms 332 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 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 9 ms 452 KB Output is correct
11 Correct 6 ms 460 KB Output is correct
12 Correct 7 ms 452 KB Output is correct
13 Correct 8 ms 332 KB Output is correct
14 Correct 755 ms 12160 KB Output is correct
15 Execution timed out 10082 ms 9896 KB Time limit exceeded
16 Halted 0 ms 0 KB -