Peter's codebook A blog full of codes

IOICamp2017 貓貓部長

Meow~

在 IOICamp2017 解過的題目

不提供傳送門

題目敘述

自己去 IOICamp 的 Judge 上去看看吧

輸入格式

第一行一個正整數 ,代表測資筆數。每筆測資兩行, 第一行兩個整數 ,第二行 個正整數

限制

$$1 \leq T \leq 100$$ $$1 \leq N,k \leq 100000$$ $$1 \leq a_{i} \leq 100000$$

輸出格式

若所有 跟相距 內位置的數字均不重複 ([i-k,i+k]) ,就輸出 Yes ,否則輸出 No

程式碼:

開 set 亂玩一通

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
#include <bits/stdc++.h>
using namespace std;

set<int> S;
vector<int> V;

int main(void) {
    int T, N, k;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--) {
        cin >> N >> k;
        for(int i=0; i<N; ++i) {
            int temp;
            cin>>temp;
            V.push_back(temp);
        }
        bool fail=false;
        for(int i=0; i<k && i<N; ++i) {
            if(S.count(V[i])) { // Fails at the beginning.
                fail=true; break;
            }
            S.insert(V[i]);
        }
        int i;
        if(!fail) {
            for(i=k; i<N; ++i) {
                if(S.count(V[i])) break;
                //else
                S.erase(V[i-k]);
                S.insert(V[i]);
            }
            fail = (i!=N);
        }
        cout << (!fail?"Yes\n":"No\n");
        V.clear(); S.clear();
    }
    return 0;
}

之前竟然寫了假解 OuO

comments powered by Disqus