結果

問題 No.2334 Distinct Cards
ユーザー pseudosodium
提出日時 2023-06-02 21:23:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,064 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 207,180 KB
最終ジャッジ日時 2025-02-13 17:35:16
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

template <typename T> istream& operator >> (istream& in, vector<T>& v) { for (auto &it:v) in >> it; return in; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (auto it:v) os << it << " "; return os; }
template <typename T1, typename T2> istream& operator >> (istream& in, pair<T1,T2>& p) { in >> p.first >> p.second; return in; }
template <typename T1, typename T2> ostream& operator << (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
// auto operator<<(ostream&o,auto&&v)->enable_if_t<!is_constructible_v<string,decltype(v)>,decltype(o<<*end(v))>{int f=0,u=&o!=&cerr;o<<"["+u;for(auto&&x:v)(f++?o<<", "+u:o)<<x;return o<<"]"+u;}
// auto operator<<(ostream&o,auto&&t)->decltype(o<<get<0>(t)){int f=0,u=&o!=&cerr;o<<"<"+u;apply([&](auto&...x){(((f++?o<<", "+u:o)<<x),...);},t);return o<<">"+u;}
template <typename T1, typename T2> void minn(T1& a, T2 b) { a = min(a,b); }
template <typename T1, typename T2> void maxx(T1& a, T2 b) { a = max(a,b); }

#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define deb(x) cerr<<#x<<"="<<x<<'\n';

const int mod = 1e9L + 7;
const int mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795;
const int raw_mango_seed = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(raw_mango_seed);

void solve() {
    int n,k; cin>>n>>k;
    vector<int> a(n); cin>>a;
    sort(all(a));
    map<int,int> m;
    int ans=k;
    for(int i=0;i<k;i++) m[a[i]]++;
    minn(ans,sz(m));
    for(int i=k;i<n;i++){
        m[a[i-k]]--;
        if(m[a[i-k]]==0)m.erase(a[i-k]);
        m[a[i]]++;
        minn(ans,sz(m));
    }
    cout<<ans<<'\n';
}

int32_t main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    cin.tie(0)->sync_with_stdio(0);
    int tc=1;
    // cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}
0