QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#257081#1955. Double RainbowsuperduchackgvWA 13ms4156kbC++202.3kb2023-11-18 23:58:412023-11-18 23:58:41

Judging History

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

  • [2023-11-18 23:58:41]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:4156kb
  • [2023-11-18 23:58:41]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define vt vector
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

typedef unsigned long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vt<int> vti;
const double Pi = acos(- 1.0);
template<typename T>ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {for(T x : vec) cout << x << ' '; cout << endl;return os;}
const int inf = INT_MAX;


void Duck(){
    int n; cin >> n;
    int k; cin >> k;
    vti a(n), cnt(k + 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    if(k * 2 > n){
        cout << 0 << endl;
        return;
    }
    deque<int> dq;
    set<int> s;
    vti cnt2(k + 1);
    for(int i = 0; i < n && s.size() < k; i++){
        dq.push_back(i);
        s.ins(a[i]);
        cnt2[a[i]]++;
        while(cnt2[a[dq.front()]] > 1 && dq.size()){
            cnt2[a[dq.front()]]--;
            dq.pop_front();
            
        }
    }
    int l = dq.front(), r = dq.back();
    //cout << debug(l) debug(r) << endl;
    for(int i = l; i <= r; i++) cnt[a[i]]--;

    bool ok = 1;
    for(int i = 1; i <= k; i++){
        if(cnt2[i] == 0 || cnt[i] == 0){
            ok = 0;
        }
    }
    int ans = n;
    if(ok) ans = r - l + 1;
    ++r;
    while(r < n){
        cnt2[a[r]]--;
        cnt[a[r]]++;
        while(cnt2[a[l]] > 1){
            cnt2[a[l]]--;
            l++;
        }
        ok = 1;
        for(int i = 1; i <= k; i++){
            if(cnt2[i] == 0 || cnt[i] == 0){
                ok = 0;
            }
        }
        if(ok) ans = min(ans, r - l + 1);
        r++;
    }
    cout << (ans == n ? 0 : ans);
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*Duck3*/
    int t = 1;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    //cin >> t;
    while(t--) Duck();
    return 0;
}
/*
Test:

*/









详细

Test #1:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

2 1
1
1

output:

1

result:

ok single line: '1'

Test #3:

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

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: 13ms
memory: 4156kb

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: 9ms
memory: 3928kb

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: 13ms
memory: 3820kb

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'