CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:borkbork
Submission time:2018-10-06 18:34:39 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:69:10: error: 'cout' in namespace 'std' does not name a type
     std::cout<<res;
          ^~~~
In file included from input/code.cpp:1:0:
/usr/include/c++/7/iostream:61:18: note: 'std::cout' declared here
   extern ostream cout;  /// Linked to standard output
                  ^~~~
input/code.cpp:70:1: error: expected declaration before '}' token
 }
 ^

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 long long res=n;
    for(size_t i=1;i<k;i++){res+=(n-i);}
    if(n==k){std::cout<<res;return 0;}
    if(s.size()==k){for(size_t i=k;i<n;i++){res+=(n-i);}std::cout<<res;return 0;}
    if(n/2<k||n<100){

    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]]++;
        for(size_t j=1;j<n-i;j++){
            
            if(!map[d[i+j]]){
                count++;
                map[d[i+j]]++;
            }
            if(count>k){break;}
            if(k<j+1){
                if(count<1+k){
                    res++;
                    
                }
            }
        }
    }

    }
    else{
    // only thing left
    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]]++;
        for(size_t j=1;j<n-i;j++){
            
            if(!map[d[i+j]]){
                count++;
                map[d[i+j]]++;
            }
            if(count>k){break;}
            if(k<j+1){
                if(count<1+k){
                    res++;
                    
                }
            }
        }
    }

    }
    }
    std::cout<<res;
}