Submission #482577

#TimeUsernameProblemLanguageResultExecution timeMemory
482577HazemLottery (CEOI18_lot)C++14
0 / 100
2 ms332 KiB
#include <bits/stdc++.h>

#define LL long long
 
 
using namespace std;
 
const int N = 1e4+1;
const LL MOD = 1e9+7;

int a[N],hashs[N];
map<int,int>mp;
set<int>st;
 
int mult(LL a,LL b){

    return (a*b)%MOD;
}
int add(LL a,LL b){

    return (a+b)%MOD;
}

int main(){
 
    int n,l;
    scanf("%d%d",&n,&l);
 
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }   

    for(int i=1;i<=n-l+1;i++){
        int prime = 23,hash = 1,power = 1;
        for(int j=i;j<=i+l-1;j++)
            hash = add(hash,mult(a[i],power)),power = mult(power,prime);
        mp[hash]++;
        hashs[i] = hash;
    }

    for(int i=1;i<=n-l+1;i++)
        printf("%d ",mp[hashs[i]]-1);
    puts("");
}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~
lot.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...