QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202839#4647. Wavy Treeyiyiyi#AC ✓71ms19404kbC++14938b2023-10-06 13:42:462023-10-06 13:42:47

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 13:42:47]
  • 评测
  • 测评结果:AC
  • 用时:71ms
  • 内存:19404kb
  • [2023-10-06 13:42:46]
  • 提交

answer

#include <bits/stdc++.h>
#include <unordered_map>
#define int long long
#define inf 1e18
#define re register
#define N 1020203
using namespace std;
const int mo=1000000007;
inline int read(){
	int x=0,w=0;char ch=getchar();
	while (!isdigit(ch))w|=ch=='-',ch=getchar();
	while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return w?-x:x;
}
int a[N],b[N];
void solve(){
	int n=read(),ans1=0,ans2=0;
	for (int i=1;i<=n;++i)a[i]=b[i]=read();
	for (int i=2;i<=n;++i)
		if (i&1){
			if (a[i]>=a[i-1])ans1+=a[i]-a[i-1]+1,a[i]=a[i-1]-1;
		}else{
			if (a[i]<=a[i-1])ans1+=a[i-1]-a[i]+1,a[i]=a[i-1]+1;
		}
	for (int i=1;i<=n;++i)a[i]=b[i];
	for (int i=2;i<=n;++i)
		if (i&1){
			if (a[i]<=a[i-1])ans2+=a[i-1]-a[i]+1,a[i]=a[i-1]+1;
		}else{
			if (a[i]>=a[i-1])ans2+=a[i]-a[i-1]+1,a[i]=a[i-1]-1;
		}
	cout<<min(ans1,ans2)<<endl;
}
signed main(){
    int T=read();
    while (T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 71ms
memory: 19404kb

input:

1000
100000
421811673 163389757 362117917 679743722 325614744 632629964 980475526 100505548 936347880 928352466 107919751 93875425 790807861 179598820 105172240 143240481 781447901 225995680 495635141 806359893 572331818 169913092 230473678 658931041 285082875 709115692 204427990 675460241 498216193...

output:

7254088195794
10532337049187
42013773340
93984668312079
304864037717
24280801657
27126085272
36045025116
3661199008116
6128224088957
27163006737
4061518843424
13450250708
39002357066
27114173348
4819422928
10116511952
29694865171
300714954028
44450326647
46689505040
19307568489
31476115190
306968957...

result:

ok 1000 lines