CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:borkbork
Submission time:2018-10-08 13:40:27 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:28:9: error: expected ',' or ';' before 'for'
         for(;j<n-i;){
         ^~~
input/code.cpp:28:15: warning: statement has no effect [-Wunused-value]
         for(;j<n-i;){
              ~^~~~
input/code.cpp:28:20: error: expected primary-expression before ')' token
         for(;j<n-i;){
                    ^

Code

#include<iostream>
#include<unordered_set>
#include<unordered_map>

int main(){
    std::ios_base::sync_with_stdio(0);std::cin.tie(NULL);
    unsigned int n,k;
    std::cin>>n>>k;
    unsigned int d[500100];
    unsigned int input;
    std::unordered_set<unsigned int> s;
    for(size_t i=0;i<n;i++){std::cin>>input;s.insert(input);d[i]=input;}
    unsigned int uniq=s.size();
    unsigned long long res=n;
    for(size_t i=1;i<k;i++){res+=(n-i);}
    if(n==k){std::cout<<res;return 0;}
    if(uniq<1+k){for(size_t i=k;i<n;i++){res+=(n-i);}std::cout<<res;return 0;}
    

    unsigned long long count=0;
    std::unordered_map<unsigned int,unsigned int> map;
    
    for(size_t i=0;i<n-k+1;i++){
        count=1;
        map.clear();
        map[d[i]]++;
        size_t j=1
        for(;j<n-i;){
            
            if(!map[d[i+j]]){
                count++;
                map[d[i+j]]++;
            }
            if(count>k){break;}
            if(k<j+1){
                if(count<1+k){
                    res++;
                    
                }
            }
            j++;
        }
        i=j-k+1;
    }
    std::cout<<res<<"\n";
}