1 条题解

  • 1
    @ 2025-1-14 13:52:26
    #include <bits/stdc++.h>
    #define inf 0x3f3f3f3f
    #define Linf 0x3f3f3f3f3f3f3f3f
    using namespace std;
    const int N = 5e5+2, M = 102, mod = 1e9+7;
    
    void add(int &a, int b) {
    	if(a + b >= mod) a = a + b - mod;
    	else if(a + b < 0) a = a + b + mod;
    	else a = a + b;
    }
    
    int n, a[N];
    int f[M];
    int ans;
    
    signed main() {
    	
    	cin >> n;
    	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    	
    	for(int d = -100; d <= 100; ++d) {
    		memset(f, 0, sizeof(f));
    		for(int i = 1; i <= n; ++i) {
    			int val = a[i] - d;
    			if(val >= 0 && val <= 100) add(f[a[i]], f[val]);
    			add(f[a[i]], 1);
    		}
    		for(int i = 0; i <= 100; ++i) add(ans, f[i]);
    		if(d != 0) add(ans, -n);
    	}
    	cout << ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    275
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    27
    已通过
    4
    上传者