fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void *wmem;
  5. char memarr[96000000];
  6. template<class S, class T> inline S min_L(S a,T b){
  7. return a<=b?a:b;
  8. }
  9. template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  10. static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  11. (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  12. (*arr)=(T*)(*mem);
  13. (*mem)=((*arr)+x);
  14. }
  15. template<class T> int longestSuffixPrefix(int As, T A[], int Bs, T B[], void *mem = wmem){
  16. int i;
  17. int k;
  18. int res;
  19. int *fail;
  20. if(As > Bs){
  21. A += As-Bs;
  22. As = Bs;
  23. }
  24. if(As < Bs){
  25. Bs = As;
  26. }
  27. walloc1d(&fail, Bs, &mem);
  28. k = fail[0] = -1;
  29. for(i=(0);i<(Bs);i++){
  30. while(k>=0 && B[k]!=B[i]){
  31. k = fail[k];
  32. }
  33. fail[i+1] = ++k;
  34. }
  35. res = 0;
  36. for(i=(0);i<(As);i++){
  37. while(res && A[i]!=B[res]){
  38. res = fail[res];
  39. }
  40. if(A[i]==B[res]){
  41. res++;
  42. }
  43. }
  44. return res;
  45. }
  46. #define main dummy_main
  47. int main(){
  48. wmem = memarr;
  49. return 0;
  50. }
  51. #undef main
  52. class Solution{
  53. public:
  54. string longestPrefix(string s){
  55. dummy_main();
  56. int len = longestSuffixPrefix(s.size()-1, s.c_str()+1, s.size()-1, s.c_str());
  57. return s.substr(0,len);
  58. }
  59. }
  60. ;
  61. // cLay varsion 20200325-1
  62.  
  63. // --- original code ---
  64. // #define main dummy_main
  65. // {}
  66. // #undef main
  67. //
  68. // class Solution {
  69. // public:
  70. // string longestPrefix(string s) {
  71. // dummy_main();
  72. // int len = longestSuffixPrefix(s.size()-1, s.c_str()+1, s.size()-1, s.c_str());
  73. // return s.substr(0,len);
  74. // }
  75. // };
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty