fork download
  1. final int mod = 1000 * 1000 * 1000 + 7;
  2. int add(int a, int b) { return (a + b) % mod; }
  3. int subtract(int a, int b) { return (a + mod - b) % mod; }
  4. int multiply(int a, int b) { return (int) ((long) a * b % mod); }
  5. int[][] interval, outside;
  6. int GLOBAL_N;
  7. boolean ok(int i, int j) {
  8. return 0 <= i && i <= j && j < GLOBAL_N;
  9. }
  10. int f_interval(int i, int j) {
  11. return ok(i, j) ? interval[i][j] : 1;
  12. }
  13. int f_outside(int i, int j) {
  14. return ok(i, j) ? outside[i][j] : 1;
  15. }
  16. public int solve(String s) {
  17. int n = s.length();
  18. GLOBAL_N = n;
  19. interval = new int[n][n];
  20. outside = new int[n][n];
  21. for (int i = n - 1; i >= 0; --i)
  22. for (int j = i; j < n; ++j) {
  23. interval[i][j] = add(f_interval(i + 1, j), f_interval(i, j - 1));
  24. if (s.charAt(i) != s.charAt(j))
  25. interval[i][j] = subtract(interval[i][j], f_interval(i + 1, j - 1));
  26. }
  27. for (int i = 0; i < n; ++i)
  28. for (int j = n - 1; j > i; --j) {
  29. outside[i][j] = add(f_outside(i - 1, j), f_outside(i, j + 1));
  30. if (s.charAt(i) != s.charAt(j))
  31. outside[i][j] = subtract(outside[i][j], f_outside(i - 1, j + 1));
  32. }
  33.  
  34. int[] ans = new int[n];
  35. for (int i = 0; i < n; ++i) {
  36. ans[i] = add(ans[i], f_outside(i - 1, i + 1));
  37. for (int j = i + 1; j < n; ++j)
  38. if (s.charAt(i) == s.charAt(j)) {
  39. int tmp = multiply(f_interval(i + 1, j - 1), f_outside(i - 1, j + 1));
  40. ans[i] = add(ans[i], tmp);
  41. ans[j] = add(ans[j], tmp);
  42. }
  43. }
  44. write(ans);
  45. int X = 0;
  46. for(int i = 0; i < n; ++i)
  47. X ^= multiply(ans[i], i + 1);
  48. return X;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
final int mod = 1000 * 1000 * 1000 + 7;
      ^
Main.java:2: error: class, interface, or enum expected
int add(int a, int b) { return (a + b) % mod; }
^
Main.java:2: error: class, interface, or enum expected
int add(int a, int b) { return (a + b) % mod; }
                                              ^
Main.java:3: error: class, interface, or enum expected
int subtract(int a, int b) { return (a + mod - b) % mod; }
                                                         ^
Main.java:4: error: class, interface, or enum expected
int multiply(int a, int b) { return (int) ((long) a * b % mod); }
                                                                ^
Main.java:6: error: class, interface, or enum expected
int GLOBAL_N;
^
Main.java:7: error: class, interface, or enum expected
boolean ok(int i, int j) {
^
Main.java:9: error: class, interface, or enum expected
}
^
Main.java:12: error: class, interface, or enum expected
}
^
Main.java:15: error: class, interface, or enum expected
}
^
Main.java:16: error: class, interface, or enum expected
public int solve(String s) {
       ^
Main.java:18: error: class, interface, or enum expected
	GLOBAL_N = n;
	^
Main.java:19: error: class, interface, or enum expected
	interval = new int[n][n];
	^
Main.java:20: error: class, interface, or enum expected
	outside = new int[n][n];
	^
Main.java:21: error: class, interface, or enum expected
	for (int i = n - 1; i >= 0; --i)
	^
Main.java:21: error: class, interface, or enum expected
	for (int i = n - 1; i >= 0; --i)
	                    ^
Main.java:21: error: class, interface, or enum expected
	for (int i = n - 1; i >= 0; --i)
	                            ^
Main.java:22: error: class, interface, or enum expected
		for (int j = i; j < n; ++j) {
		                ^
Main.java:22: error: class, interface, or enum expected
		for (int j = i; j < n; ++j) {
		                       ^
Main.java:24: error: class, interface, or enum expected
			if (s.charAt(i) != s.charAt(j))
			^
Main.java:26: error: class, interface, or enum expected
		}
		^
Main.java:27: error: class, interface, or enum expected
	for (int i = 0; i < n; ++i)
	                ^
Main.java:27: error: class, interface, or enum expected
	for (int i = 0; i < n; ++i)
	                       ^
Main.java:28: error: class, interface, or enum expected
		for (int j = n - 1; j > i; --j) {
		                    ^
Main.java:28: error: class, interface, or enum expected
		for (int j = n - 1; j > i; --j) {
		                           ^
Main.java:30: error: class, interface, or enum expected
			if (s.charAt(i) != s.charAt(j))
			^
Main.java:32: error: class, interface, or enum expected
		}
		^
Main.java:35: error: class, interface, or enum expected
	for (int i = 0; i < n; ++i) {
	^
Main.java:35: error: class, interface, or enum expected
	for (int i = 0; i < n; ++i) {
	                ^
Main.java:35: error: class, interface, or enum expected
	for (int i = 0; i < n; ++i) {
	                       ^
Main.java:37: error: class, interface, or enum expected
		for (int j = i + 1; j < n; ++j)
		^
Main.java:37: error: class, interface, or enum expected
		for (int j = i + 1; j < n; ++j)
		                    ^
Main.java:37: error: class, interface, or enum expected
		for (int j = i + 1; j < n; ++j)
		                           ^
Main.java:40: error: class, interface, or enum expected
				ans[i] = add(ans[i], tmp);
				^
Main.java:41: error: class, interface, or enum expected
				ans[j] = add(ans[j], tmp);
				^
Main.java:42: error: class, interface, or enum expected
			}
			^
Main.java:45: error: class, interface, or enum expected
	int X = 0;
	^
Main.java:46: error: class, interface, or enum expected
	for(int i = 0; i < n; ++i)
	^
Main.java:46: error: class, interface, or enum expected
	for(int i = 0; i < n; ++i)
	               ^
Main.java:46: error: class, interface, or enum expected
	for(int i = 0; i < n; ++i)
	                      ^
Main.java:48: error: class, interface, or enum expected
	return X;
	^
Main.java:49: error: class, interface, or enum expected
}
^
42 errors
stdout
Standard output is empty