competitive-programming-java-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub shun0923/competitive-programming-java-library

:heavy_check_mark: library/Kmp.java

Depends on

Verified with

Code

package library;

import java.util.*;
import library.FastIO;

final class Kmp {
	// O(|S|)
	public final int a[];
	public final int kmp[];
	public Kmp(String s) { this(s.toCharArray()); }
	public Kmp(char[] c) { this(FastIO.charToInt(c)); }
	public Kmp(int[] a) {
		this.a = a;
		kmp = new int[a.length + 1];
		kmp[0] = -1;
		int r = -1;
		for(int l = 0; l < a.length; l ++) {
			while(r != -1 && a[l] != a[r]) r = kmp[r];
			r ++;
			if(l + 1 < a.length && a[l + 1] == a[r]) kmp[l + 1] = kmp[r];
			else kmp[l + 1] = r;
		}

	}

	// return all the occurrences of S in T
	// O(|S|+|T|)
	public final int[] match(String t) { return match(t.toCharArray()); }
	public final int[] match(char[] c) { return match(FastIO.charToInt(c)); }
	public final int[] match(int[] b) {
		ArrayList<Integer> match = new ArrayList<Integer>();
		int j = 0;
		for(int i = 0; i < b.length; ) {
			while(i != b.length && j != a.length && b[i] == a[j]) { i ++; j ++; }
			if(j == a.length) match.add(i - j);
			j = kmp[j];
			if(j == -1) { i ++; j ++; }
		}
		int matchList[] = new int[match.size()];
		for(int i = 0; i < match.size(); i ++) matchList[i] = match.get(i);
		return matchList;
	}
}
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/user_defined.py", line 71, in bundle
    return subprocess.check_output(shlex.split(command))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.
Back to top page