QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#284950#7942. $K$ Subsequencesucup-team1074#WA 1ms3944kbC++98787b2023-12-16 15:50:272023-12-16 15:50:28

Judging History

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

  • [2023-12-16 15:50:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3944kb
  • [2023-12-16 15:50:27]
  • 提交

answer

#include <cstdio>
#include <cstring>

#define N 200000

using namespace std;

int n,k;
int arr[N+5];
int ans[N+5];
int s[N+5];

int find(bool u){
	int m=u?0:N+5;
	int ans=1;
	for(int i=1;i<=k;i++){
		if(u){
			if(m<s[i]){
				ans=i;
				m=s[i];
			}
		}
		else {
			if(m>s[i]){
				ans=i;
				m=s[i];
			}
		}
	}
	return ans;
}

void slv(){
	memset(arr,0,sizeof arr);
	memset(ans,0,sizeof ans);
	memset(s,0,sizeof s);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;scanf("%d",&arr[i++]));
	for(int i=1,t;i<=n;i++){
		t=find(arr[i]==-1);
		ans[i]=t;
		if(arr[i]==1)s[t]++;
		else s[t]=0;
	}
	for(int i=1;i<=n;printf("%d ",ans[i++]));
	printf("\n");
	return ;
}

int main(){
	int t;
	scanf("%d",&t);
	for(int i=1;i<=t;slv(),i++);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3944kb

input:

5
3 2
1 -1 1
4 2
-1 1 1 -1
7 3
1 1 1 1 1 1 1
10 3
1 1 1 1 -1 -1 1 1 1 1
12 4
1 1 1 1 -1 -1 -1 -1 1 1 1 1

output:

1 1 1 
1 1 2 1 
1 2 3 1 2 3 1 
1 2 3 1 1 2 1 2 1 2 
1 2 3 4 1 2 3 4 1 2 3 4 

result:

wrong answer Jury found better answer than participant (test case 4)