| Task: | Taulukko |
| Sender: | borkbork |
| Submission time: | 2018-10-02 17:10:56 +0300 |
| Language: | C++ |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:28:18: error: redeclaration of 'unsigned int last'
unsigned int last=0;
^~~~
input/code.cpp:26:18: note: 'unsigned int last' previously declared here
unsigned int last=0;
^~~~
input/code.cpp:25:24: warning: unused variable 'len' [-Wunused-variable]
unsigned long long len=0;
^~~
input/code.cpp:65:1: error: expected '}' at end of input
}
^Code
#pragma GCC optimize ("03")
#include<iostream>
#include<map>
unsigned int d[500100];
// for(size_t i=0;i<n;i++){std::cout<<d[i]<<" ";}
// i could also try to solve this with
// rolling through the array in o(n)
// o(n) isn't probably possible
int main() {
unsigned int n,k;
unsigned long long res;
std::cin>>n>>k;
for(size_t i=0;i<n;i++){std::cin>>d[i];}
// res = amount of subarrays to k
res=n;//std::cout<<"res: "<<res<<"\n";
for(size_t i=2;i<k+1;i++){
res+=(n-i+1);//std::cout<<"res: "<<res<<"\n";
}
// now we have to compute all subarrays
// with higher size than k
unsigned long long len=0;
unsigned int last=0;
unsigned long long count=0;
unsigned int last=0;
std::map<unsigned int,unsigned int> map;
for(size_t i=0;i<n-k;i++){
count=k;
if(last==1){
map.clear();
for(size_t it=0;it<k;it++){
map[d[i+it]]++;
}
}
else {
map[d[i-1]]=0;
}
last=0;
for(size_t j=k;j<n-i+1;j++){
if(!map[d[i+j]]){
count++; // amount of different numbers
map[d[i+j]]++;
}
else{if(d[i+j]==d[i]){
last=1;
}
if(count>k){break;}
if(k<j+1){ // if subarray is larger than k
if(count<1+k){
res++;
}
}
}
}
std::cout<<res;
}