Submission #75084643


Source Code Expand

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

#define int long long 

const int N=2e5+5;

bool st;
int t,n,a[N],m,c[N],d[N];
bool ed;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--) {
		cin>>n>>m;a[n+1]=0;
		for(int i=1;i<=n;i++) cin>>a[i];
		int x=n/2;
		int sum=0;
		for(int i=1;i<=x;i++) c[i]=((a[i]-a[n+1-i])%m+m)%m;
		for(int i=1;i<=x;i++) d[i]=(c[i-1]-c[i]+m)%m;
		d[x+1]=c[x];
		sort(d+1,d+x+2);
		for(int i=1;i<=x+1;i++) sum+=d[i];
		int temp=sum/m;
		for(int i=0;i<temp;i++) sum-=d[x+1-i];
		cout<<sum<<'\n';
	}
	return 0;
}

Submission Info

Submission Time
Task F - Make it Palindrome 2
User wallacewan
Language C++23 (GCC 15.2.0)
Score 525
Code Size 608 Byte
Status AC
Exec Time 30 ms
Memory 6848 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3644 KiB
01_handmade_00.txt AC 11 ms 6748 KiB
01_handmade_01.txt AC 11 ms 3628 KiB
01_handmade_02.txt AC 12 ms 6720 KiB
01_handmade_03.txt AC 13 ms 6748 KiB
01_handmade_04.txt AC 13 ms 6720 KiB
02_random_00.txt AC 15 ms 6100 KiB
02_random_01.txt AC 18 ms 6740 KiB
02_random_02.txt AC 2 ms 3808 KiB
02_random_03.txt AC 18 ms 6848 KiB
02_random_04.txt AC 3 ms 4160 KiB
02_random_05.txt AC 18 ms 6848 KiB
02_random_06.txt AC 18 ms 6620 KiB
02_random_07.txt AC 18 ms 6744 KiB
02_random_08.txt AC 9 ms 5048 KiB
02_random_09.txt AC 19 ms 6848 KiB
02_random_10.txt AC 30 ms 3620 KiB
02_random_11.txt AC 19 ms 3688 KiB
02_random_12.txt AC 13 ms 3680 KiB
02_random_13.txt AC 13 ms 3564 KiB
02_random_14.txt AC 13 ms 3676 KiB
02_random_15.txt AC 13 ms 3676 KiB
02_random_16.txt AC 14 ms 3776 KiB
02_random_17.txt AC 14 ms 3648 KiB