30分 打的暴力分 后面全TLE 求大佬给思路
查看原帖
30分 打的暴力分 后面全TLE 求大佬给思路
545516
Habseligkeit楼主2022/10/23 13:41
#include<bits/stdc++.h>
using namespace std;
const int M = 1e7 + 10;
const int INF = 998244353;
typedef long long ll;
ll n , k , a[M] , ans; 

void work(int m) {
	for(int i = 1; i <= n; i ++) {
		if(a[i] + m >= abs(a[i]))
		  ans = (ans + (a[i] + m) * (a[i] + m)) % INF;
		else ans = (ans + (a[i] + 1) * (a[i] + 1)) % INF;
	}
}

int main() {
	scanf("%lld %lld" , &n , &k);
	for(int i = 1; i <= n; i ++) 
		scanf("%lld" , &a[i]);
	for(int i = 1; i <= k; i ++)
	  work(i);
	printf("%lld\n" , ans);
	return 0;
}
2022/10/23 13:41
加载中...