# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
82330 | wzy | Lottery (CEOI18_lot) | C++11 | 1488 ms | 11080 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Fix one diagonal and use prefix sum of a boolean matrix such that the position (i,j) represents mismatch of i and j
is better to code if the diagonal is (i , 1) - > (i+1 , 2) -> (i+2 , 3) ...
*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
int n , l , q , a[10002] , k[101] , v[10002], r[10002][101] , pos[10002] , ans[10002][101], k2[101];
int32_t main(){
scanf("%d%d" , &n , &l);
for(int i = 1 ; i <= n;i ++) scanf("%d" , &a[i]);
scanf("%d" , &q);
for(int i = 1 ; i <= q ;i ++) scanf("%d" , &k[i]), k2[i] = k[i];
sort(k + 1 , k + 1 + q);
for(int i = 1 ; i <= q; i ++) pos[k[i]] = i;
// fix the diagonal
v[0] = 0;
for(int i = 1 ; i <= n; i ++){
pii curr = pii(i, 1);
int sz = 0;
while(curr.F <= n && curr.S <= n){
v[++sz] = (a[curr.F] != a[curr.S]);
curr.F++ , curr.S++;
}
curr = pii(i ,1);
for(int j = 1 ; j <= sz; j++){
v[j] += v[j-1];
}
for(int j = 1 ; j <= sz ;j ++){
if(j>= l){
pii cc = pii(i+j-1 , j);
int U = v[j]-v[j-l];
if(cc.F - l +1 == cc.S - l + 1) continue;
int L = 1 , R = q;
int ansj = -1;
while(L<=R){
int mid = (L + R)/2;
if(k[mid] >= U){
ansj = mid;
R = mid - 1;
}
else L = mid + 1;
}
//cout<<cc.F - l + 1 <<" " << cc.S - l + 1 <<" " << U << " "<<ansj << " " << k[ansj] << endl;
if(ansj != -1){
r[cc.F - l + 1][ansj]++;
r[cc.S - l + 1][ansj]++;
}
}
}
}
for(int i = 1 ; i<= n; i ++){
for(int j = 1 ; j <= q;j++){
r[i][j] += r[i][j-1];
}
}
for(int j = 1 ; j <= q; j ++){
for(int i = 1 ; i <= n-l+1;i ++){
printf("%d ", r[i][pos[k2[j]]]);
}
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |