Submission #938259

# Submission time Handle Problem Language Result Execution time Memory
938259 2024-03-05T03:51:00 Z UmairAhmadMirza Three Friends (BOI14_friends) C++17
0 / 100
500 ms 35736 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int const N=2e6+5;
int const mod=1e9+7;
int const base=727;
int Hash[N];
int pw[N];
int n;
string s;
void pre(){
  pw[0]=1;
  for(int i=1;i<=n;i++)
    pw[i]=(pw[i-1]*base)%mod;
}
void make_Hash(){
  for(int i=1;i<=n;i++)
    Hash[i]=((Hash[i-1]*base)+s[i-1])%mod;
}
int compute_Hash(int l,int r){
  return ((Hash[r] - ((Hash[l]*pw[r-l])%mod) )+mod)%mod;
}
int org_Hash1(int e){
  if(e>n/2)
    return Hash[n/2];
  int h=(Hash[e-1]*pw[((n/2)+1)-e])%mod;
  h+=compute_Hash(e,(n/2)+1);
  h%=mod;
  return h;
}
int org_Hash2(int e){
  if(e<=(n/2)+1)
    return compute_Hash((n/2)+1,n);
  int h=(compute_Hash((n/2),e-1)*pw[n-e])%mod;
  h+=compute_Hash(e,n);
  h%=mod;
  return h;
}
string make_str(int p){
  string st="";
  int i=0;
  while(st.size()<(n/2)){
    if(i==p-1)
      continue;
    st+=s[i];
    i++;
  }
  return st;
}
signed main() 
{
  cin>>n;
  cin>>s;
  if(n%2==0){
    cout<<"NOT POSSIBLE\n";
    return 0;
  }
  pre();
  make_Hash();
  int rem=0;
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(org_Hash1(i)==org_Hash2(i)){
      rem=i;
      cnt++;
    }
  }
  if(cnt==0)
    cout<<"NOT POSSIBLE"<<endl;
  else if(cnt>1)
    cout<<"NOT UNIQUE"<<endl;
  else
    cout<<make_str(rem)<<endl;
  return 0;
}

Compilation message

friends.cpp: In function 'std::string make_str(long long int)':
friends.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   42 |   while(st.size()<(n/2)){
      |         ~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 35736 KB Time limit exceeded
2 Halted 0 ms 0 KB -