求调
  • 板块灌水区
  • 楼主_FarmerJohn_
  • 当前回复1
  • 已保存回复2
  • 发布时间2024/7/24 16:39
  • 上次更新2024/7/24 17:21:50
查看原帖
求调
628365
_FarmerJohn_楼主2024/7/24 16:39

TLE了,不知为何

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NN = 40;
int N, M, Ans;
int A[NN];
map<int, bool> Vis;

void Search(int num, int index){
	if(index == N + 1)
		return ;
	
	// 选
	if(Vis[(num + A[index]) % M] == false)
		Vis[(num + A[index]) % M] = true,
		Ans = max(Ans, (num + A[index]) % M),
		Search((num + A[index]) % M, index + 1);
	
	// 不选
	Search(num, index + 1);
}

signed main(){
	cin >> N >> M;
	for(int i = 1; i <= N; i ++)
		cin >> A[i];
	
//	timespec begin;
//	clock_gettime(CLOCK_MONOTONIC, &begin);
	
	Search(0, 1);
	
	printf("%lld", Ans);
	
//	timespec end;
//	clock_gettime(CLOCK_MONOTONIC, &end);
//	printf("\n%.5lf", (double)(end.tv_nsec-begin.tv_nsec)/((double) 1e9) + (double)(end.tv_sec-begin.tv_sec));
	return 0;
}
2024/7/24 16:39
加载中...