牛客的答案和题解做的真的较差。看看隔壁力扣。
牛客能不能在判错时提供一下测试用例呀
提示我case通过18%
但是我真的不知道是哪里不过?
对比了一下题解区正确答案。我感觉写的是一样的。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
if (size <= 0)
return;
int input[] = new int[size];
for (int i = 0; i < size; i++)
input[i] = sc.nextInt();
long ans = 0;
long m = 998244353L;
quickSort(input, 0, size - 1);
int mid = size / 2;
for (int i = 0; i < mid; i++) {
ans = ((long) input[i] + ans) % m;
}
for (int i = mid; i < size; i++) {
ans = ((long) input[i] * ans) % m;
}
System.out.println(ans);
}
private static void quickSort(int[] input, int left, int right) {
int pivot = partition(input, left, right);
if (left < pivot - 1) {
quickSort(input, left, pivot - 1);
}
if (pivot < right) {
quickSort(input, pivot, right);
}
}
private static int partition(int[] input, int left, int right) {
int mid = left + (right - left) / 2;
int tmp = input[mid];
while (left <= right) {
while (input[left] < tmp) {
left++;
}
while (input[right] > tmp) {
right--;
}
swap(input, left, right);
if (left <= right) {
left++;
right--;
}
}
return left;
}
private static void swap(int[] input, int a, int b) {
int tmp = input[a];
input[a] = input[b];
input[b] = tmp;
}
}