为什么你们只AC了前三个,我是只WA了前三个,来个大佬看看求求了QAQ
查看原帖
为什么你们只AC了前三个,我是只WA了前三个,来个大佬看看求求了QAQ
1096827
AC_or_suicide楼主2023/11/2 15:12
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main{
	static int arr[] = new int[100004];
	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	static int count = 0;
	static int l = 1000000007;
	static int max = 0;
	public static void main(String[] args) throws IOException{
		int n = nextInt();
		for(int i = 1;i <= n;i++) {
			int number = nextInt();
			if(number > max) {
				max = number;
			}
			arr[number]++;
		}
		for(int i = 2;i <= max;i++) {
			if(arr[i] >= 2) {
				for(int j = 0;j <= i / 2;j++) {
					int number = i - j;
					if(j == number && arr[j] >= 2) {
						int nums1 = method(arr[i]);
						int nums2 = method(arr[j]);
						count = (count + (nums1 * nums2)) % l;
					}else if(arr[number] >= 1 && arr[j] >= 1) {
						int nums1 = method(arr[i]);
						count = (count + (nums1 * (arr[number] % l) * (arr[j] % l))) % l;
					}
				}
			}
		}
		System.out.println(count);
	}
	
	public static int method(int n) {
		return (n * (n - 1) / 2) % l;
	}
	
	
	public static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}
}

2023/11/2 15:12
加载中...