QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#284981#7942. $K$ Subsequencesucup-team1074#TL 2ms6256kbC++23858b2023-12-16 16:00:502023-12-16 16:00:50

Judging History

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

  • [2023-12-16 16:00:50]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:6256kb
  • [2023-12-16 16:00:50]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
#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;
}
//1 1 -1 1 1
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]--;
		s[t] = max(0 , s[t]);
	}
	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: 100
Accepted
time: 2ms
memory: 6256kb

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 1 1 1 2 3 
1 2 3 4 1 2 3 4 1 2 3 4 

result:

ok Correct (5 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

18434
10 1
-1 1 1 -1 -1 1 -1 -1 1 1
10 2
-1 -1 -1 1 1 -1 1 1 1 1
10 2
1 -1 -1 -1 -1 1 1 -1 1 1
10 7
1 1 -1 1 -1 1 1 -1 -1 1
9 1
-1 1 -1 1 1 -1 1 -1 1
8 1
-1 -1 -1 -1 1 1 -1 -1
10 3
-1 -1 -1 1 1 1 1 -1 -1 -1
9 1
1 -1 -1 1 -1 -1 -1 -1 -1
10 10
-1 1 1 1 1 1 1 1 1 1
10 4
-1 1 -1 1 -1 1 1 -1 1 1
9 3
1 1 ...

output:

1 1 1 1 1 1 1 1 1 1 
1 1 1 1 2 1 1 1 2 1 
1 1 1 1 1 1 2 1 1 1 
1 2 1 1 1 1 3 1 2 1 
1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 
1 1 1 1 2 3 1 1 1 2 
1 1 1 1 1 1 1 1 1 
1 1 2 3 4 5 6 7 8 9 
1 1 1 1 1 1 2 1 1 3 
1 2 1 2 1 1 1 1 1 
1 2 1 1 3 4 1 1 
1 1 2 3 4 5 6 7 1 1 
1 1 1 1 1 1 1 2 1 
1 1 1 1 1 1 1 1 1 
1 2...

result: