제출 #1033214

#제출 시각아이디문제언어결과실행 시간메모리
1033214vjudge1Lottery (CEOI18_lot)C++17
100 / 100
480 ms12112 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n,leng; cin>>n>>leng; int a[n+1]; for(int q=1;q<=n;q++){ cin>>a[q]; } int q; cin>>q; pair<int,int>tny[q+1]; for(int w=1;w<=q;w++){ cin>>tny[w].first; tny[w].second=w; } sort(tny+1,tny+q+1); int pos[leng+1]; memset(pos,-1,sizeof pos); for(int w=1;w<=q;w++){ if(pos[tny[w].first]==-1){ pos[tny[w].first]=w; } } for(int w=leng-1;w>=0;w--){ if(pos[w]==-1){ pos[w]=pos[w+1]; } } int cnt[q+1][n+1]; memset(cnt,0,sizeof cnt); for(int w=1;w<=n;w++){ int l=1,r=w+1; int diff=0; if(r+leng-1>n)break; for(int j=0;j<leng;j++){ if(a[l+j]!=a[r+j]){ diff++; } } cnt[pos[diff]][l]++; cnt[pos[diff]][r]++; while(r+leng<=n){ if(a[l+leng]!=a[r+leng]){ diff++; } if(a[l]!=a[r]){ diff--; } l++,r++; cnt[pos[diff]][l]++; cnt[pos[diff]][r]++; } } for(int w=2;w<=q;w++){ for(int e=1;e<=n;e++){ cnt[w][e]+=cnt[w-1][e]; } } int ans[q+1][n+1]; for(int w=1;w<=q;w++){ for(int e=1;e<=n;e++){ ans[tny[w].second][e]=cnt[w][e]; } } for(int w=1;w<=q;w++){ for(int e=1;e<=n-leng+1;e++){ cout<<ans[w][e]<<" "; } cout<<endl; } }
#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...