QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357901#6828. Heirloom Paintingcrsfaa#WA 22ms3760kbC++141.0kb2024-03-19 14:45:462024-03-19 14:45:46

Judging History

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

  • [2024-03-19 14:45:46]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3760kb
  • [2024-03-19 14:45:46]
  • 提交

answer

#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int mxn=2e6+5;
int a[mxn];
deque<pair<int,int>> q;
int sum,k;
void push(int c)
{
	if(q.size()&&c==q.back().first)
		sum-=(q.back().second+k-1)/k,
		q.back().second++,
		sum+=(q.back().second+k-1)/k;
	else
		sum++,q.push_back({c,1});
}
void pop()
{
	if(q.front().second==1)
		sum--,q.pop_front();
	else
		sum-=(q.back().second+k-1)/k,
		q.back().second--,
		sum+=(q.back().second+k-1)/k;
}
int main()
{	
	int T=read();
	while(T--)
	{
		q.clear();
		sum=0;
		int n=read(),m=read(),i,mn=1e9;
		k=read();
		for(i=1;i<=n;i++)
			a[i]=a[i+n]=read();
		for(i=n*2;i>n;i--)
			push(a[i]);
		for(;i;i--)
		{
			pop();
			push(a[i]);
			if(q.back().second>=k)
				mn=min(mn,sum);
		}
		printf("%d\n",mn==1e9?-1:mn);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

3
11 4 2
1 1 1 2 2 3 3 3 4 4 1
5 2 1
1 2 1 2 1
6 2 2
1 2 1 2 1 2

output:

6
5
-1

result:

ok 3 number(s): "6 5 -1"

Test #2:

score: 0
Accepted
time: 18ms
memory: 3652kb

input:

62500
16 2 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 1
2 2 2 1 1 1 1 ...

output:

16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
...

result:

ok 62500 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

3036
16 2 1
1 1 2 1 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
2 1 2 1 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
1 2 2 1 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
2 2 2 1 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
1 1 1 2 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
2 1 1 2 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
1 2 1 2 1 2 1 1 1 1 2 1 2 2 2 2
16 2 1
2 2 1 2 1 2 1 1...

output:

16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
...

result:

ok 3036 numbers

Test #4:

score: -100
Wrong Answer
time: 22ms
memory: 3704kb

input:

62500
16 2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1
16 2 2
2 2 2 1 1 1 1 ...

output:

8
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
8
-1
-1
-1
9
-1
-1
-1
10
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
10
-1
-1
-1
9
-1
-1
-1
8
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
8
-1
-1
-1
9
-1
-1
-1
10
-1
-1
-1
10
-1
-1
-1
9
-1
-1
-1
10
-1
-1
-1
11
-1
-1
-1
10
-1
-1
-1
10
-1
-1
-1
9
-1
-1
-1
9
-1
-1
-1
10
-1
...

result:

wrong answer 2nd numbers differ - expected: '9', found: '-1'