Submission #723556

#TimeUsernameProblemLanguageResultExecution timeMemory
723556penguin133Lottery (CEOI18_lot)C++17
45 / 100
727 ms65536 KiB
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
vector < vector <int> > pref;
vector <int> ft;
int n, k, q;
vector < vector <int> > mp;
int A[10005];
 
void solve(){
	cin >> n >> k;
	ft.resize(n+1);
	pref.resize(n-k+2);
	for(int i=0;i<n-k+2;i++)pref[i].resize(k+1);
	for(int i=1;i<=n;i++){
		cin >> A[i];
	}
	for(int i=1;i<=n;i++){
		for(auto &j : ft)j = 0;
		for(int j=1;j<=n-i;j++){
			if(A[j] != A[i+j])continue;
			int a = j, b = i + j;
			int lb = 1 + max(0, b - (n - k + 1));
			int ub = min(a, k);
			
			//cerr << i << ' ' << j[a] << ' ' << j[b] << ' ' << j[b] - j[a] << ' ' << lb << ' ' << ub << ' ' << ft[j[b]-j[a]].size() << '\n';
			if(lb > ub)continue;
			ft[a-ub+1]++;
			ft[a-lb+2]--;
		}
		for(int j=1;j<=n-k-i+1;j++){
			ft[j] += ft[j-1];
			//cout << ft[j] << ' ';
			pref[j][k-ft[j]]++;
			pref[j+i][k-ft[j]]++;
		}
		//cout << '\n';
	}
	for(int i=1;i<n-k+2;i++){
		for(int j=1;j<=k;j++)pref[i][j] += pref[i][j-1];
		//for(int j=0;j<=k;j++)cerr << pref[i][j] << ' ';
		//cerr << '\n';
	}
	cin >> q;
	while(q--){
		int x; cin >> x;
		for(int i=1;i<=n-k+1;i++)cout << pref[i][x] << ' ';
		cout << '\n';
	}
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message (stderr)

lot.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main(){
      | ^~~~
#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...