QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#46680 | #1955. Double Rainbow | hidder | WA | 3ms | 4132kb | C++20 | 1.3kb | 2022-08-30 20:39:05 | 2022-08-30 20:39:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=s*10+(ch-'0'),ch=getchar();
return s*w;
}
void write(int x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,k,tip[10005],num[10005],www[10005],ans=1e6,s=1;
deque<int> c;
set<int> j;
int check(){
for(int i=1;i<=k;i++){
if(www[i]==num[i]){return 0;}
}
return 1;
}
int main(){
n=read();k=read();
for(int i=1;i<=n;i++){
tip[i]=read();
num[tip[i]]++;
}
int pos=1;
while(pos<=n-k+1){
if(j.size()==k){
if(check()){if(c.size()<ans){ans=c.size();}}
memset(www,0,sizeof(www));
j.clear();
c.clear();
if(ans==k){break;}
s++;
pos=s;
}
if(c.empty()){c.push_back(tip[pos]);j.insert(tip[pos]);www[tip[pos]]++;pos++;}
else{
if(c.front()!=tip[pos]){c.push_back(tip[pos]);j.insert(tip[pos]);www[tip[pos]]++;pos++;}
else{c.pop_front();c.push_back(tip[pos]);pos++;s++;}
}
}
if(ans==1e6){printf("0\n");}
else{printf("%d\n",ans);}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3704kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3828kb
input:
2 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
10000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 4132kb
input:
10000 5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...
output:
5000
result:
ok single line: '5000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
10000 5000 5000 4999 4998 4997 4996 4995 4994 4993 4992 4991 4990 4989 4988 4987 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943...
output:
5000
result:
ok single line: '5000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4056kb
input:
10000 4999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...
output:
0
result:
wrong answer 1st lines differ - expected: '4999', found: '0'