Submission #24318618
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<ll>>;
int main() {
ll n,k;
cin>>n>>k;
vector<ll> c(n+1);
map<ll,ll> M;
REP1(i,n){
cin >> c[i];
M[c[i]]= 0;
}
ll ans = 0;
for (ll i = 1; i <= k; i++) {
if(M[c[i]]==0){
ans++;
}
M[c[i]]++;
}
if(n-k==0){
cout << ans << endl;
return 0;
}
ll sans = ans;
ll dans = ans;
for (ll i = 2; i <= n-k+1; i++) {
M[c[i-1]]--;
if(M[c[i-1]]==0){
dans--;
}
M[c[i+k-1]]++;
if(M[c[i+k-1]]==1){
dans++;
}
sans = max(sans, dans);
}
cout << sans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Colorful Candies |
| User | takkey |
| Language | C++ (GCC 9.2.1) |
| Score | 300 |
| Code Size | 1117 Byte |
| Status | AC |
| Exec Time | 427 ms |
| Memory | 24312 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 6 ms | 3608 KiB |
| 001.txt | AC | 427 ms | 24312 KiB |
| 002.txt | AC | 362 ms | 17504 KiB |
| 003.txt | AC | 94 ms | 5556 KiB |
| 004.txt | AC | 96 ms | 5536 KiB |
| 005.txt | AC | 343 ms | 24144 KiB |
| 006.txt | AC | 306 ms | 17280 KiB |
| 007.txt | AC | 96 ms | 5480 KiB |
| 008.txt | AC | 312 ms | 13912 KiB |
| 009.txt | AC | 301 ms | 13056 KiB |
| 010.txt | AC | 330 ms | 15572 KiB |
| 011.txt | AC | 293 ms | 11288 KiB |
| 012.txt | AC | 95 ms | 5476 KiB |
| 013.txt | AC | 97 ms | 5544 KiB |
| 014.txt | AC | 95 ms | 5520 KiB |
| 015.txt | AC | 97 ms | 5408 KiB |
| 016.txt | AC | 150 ms | 11208 KiB |
| 017.txt | AC | 109 ms | 9428 KiB |
| 018.txt | AC | 140 ms | 9764 KiB |
| 019.txt | AC | 155 ms | 6332 KiB |
| 020.txt | AC | 229 ms | 13216 KiB |
| example0.txt | AC | 2 ms | 3596 KiB |
| example1.txt | AC | 2 ms | 3556 KiB |
| example2.txt | AC | 2 ms | 3420 KiB |