Submission #1114269

# Submission time Handle Problem Language Result Execution time Memory
1114269 2024-11-18T13:21:22 Z epicci23 Sličnost (COI23_slicnost) C++17
17 / 100
250 ms 199112 KB
#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;

const int N = 5005;

void _(){
  int n,k,q;
  cin >> n >> k >> q;
  int a[n+5],b[n+5];
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n;i++) cin >> b[i];
  
  bitset<N> bs[N];

  for(int i=1;i+k-1<=n;i++) for(int j=i;j<=i+k-1;j++) bs[i][a[j]]=1;
  	
  int ans[n+5][n+5],tot[n+5];
  memset(ans,-1,sizeof(ans));
  memset(tot,0,sizeof(tot));
  

  for(int i=1;i+k-1<=n;i++){
  	int res = 0,p = 0;
  	while(p<n){
  	  p++;
  	  if(bs[i][b[p]]) res++;
  	  if(p>k && bs[i][b[p-k]]) res--;
  	  if(p>=k){
  	  	ans[i][p-k+1]=res;
  	  	tot[res]++;
  	  }
  	}
  }
  
  for(int i=k;i>=0;i--){
  	if(tot[i]){
  	  cout << i << ' ' << tot[i] << '\n';
  	  break;
  	}
  }

  while(q--){
  	int ind; cin >> ind;
   
    for(int i=1;i<=n;i++) if(ans[ind+1][i]!=-1) tot[ans[ind+1][i]]--;
    if(ind>=k){
    	for(int i=1;i<=n;i++) if(ans[ind-k+1][i]!=-1) tot[ans[ind-k+1][i]]--;
    }

    bs[ind+1][a[ind+1]]=0;
    if(ind>=k) bs[ind-k+1][a[ind]]=0;
    swap(a[ind],a[ind+1]);
    bs[ind+1][a[ind+1]]=1;
    if(ind>=k) bs[ind-k+1][a[ind]]=1;
    
    int p = 0, res = 0;
    while(p<n){
  	  p++;
  	  if(bs[ind+1][b[p]]) res++;
  	  if(p>k && bs[ind+1][b[p-k]]) res--;
  	  if(p>=k){
  	  	//cout << ind+1 << ' ' << p-k+1 << ' ' << res << '\n';
  	  	ans[ind+1][p-k+1]=res;
  	  	tot[res]++;
  	  }
  	}
    
    if(ind>=k){
	    p = 0, res = 0;
	    while(p<n){
	  	  p++;
	  	  if(bs[ind-k+1][b[p]]) res++;
	  	  if(p>k && bs[ind-k+1][b[p-k]]) res--;
	  	  if(p>=k){
	  	  	//cout << ind-k+1 << ' ' << p-k+1 << ' ' << res << '\n';
	  	  	ans[ind-k+1][p-k+1]=res;
	  	  	tot[res]++;
	  	  }
	  	}
    } 

    for(int i=k;i>=0;i--){
     if(tot[i]){
  	  cout << i << ' ' << tot[i] << '\n';
  	  break;
  	 }
    }
  }
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
16 Correct 218 ms 190792 KB Output is correct
17 Correct 246 ms 188304 KB Output is correct
18 Correct 188 ms 188744 KB Output is correct
19 Correct 212 ms 191044 KB Output is correct
20 Correct 250 ms 199112 KB Output is correct
21 Correct 224 ms 184676 KB Output is correct
22 Correct 195 ms 197752 KB Output is correct
23 Correct 221 ms 182068 KB Output is correct
24 Correct 221 ms 191816 KB Output is correct
25 Correct 172 ms 180620 KB Output is correct
26 Correct 192 ms 195204 KB Output is correct
27 Correct 191 ms 183928 KB Output is correct
28 Correct 176 ms 183368 KB Output is correct
29 Correct 174 ms 195420 KB Output is correct
30 Correct 156 ms 190104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
16 Correct 218 ms 190792 KB Output is correct
17 Correct 246 ms 188304 KB Output is correct
18 Correct 188 ms 188744 KB Output is correct
19 Correct 212 ms 191044 KB Output is correct
20 Correct 250 ms 199112 KB Output is correct
21 Correct 224 ms 184676 KB Output is correct
22 Correct 195 ms 197752 KB Output is correct
23 Correct 221 ms 182068 KB Output is correct
24 Correct 221 ms 191816 KB Output is correct
25 Correct 172 ms 180620 KB Output is correct
26 Correct 192 ms 195204 KB Output is correct
27 Correct 191 ms 183928 KB Output is correct
28 Correct 176 ms 183368 KB Output is correct
29 Correct 174 ms 195420 KB Output is correct
30 Correct 156 ms 190104 KB Output is correct
31 Runtime error 20 ms 11080 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
16 Correct 3 ms 3420 KB Output is correct
17 Incorrect 4 ms 3408 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
16 Correct 218 ms 190792 KB Output is correct
17 Correct 246 ms 188304 KB Output is correct
18 Correct 188 ms 188744 KB Output is correct
19 Correct 212 ms 191044 KB Output is correct
20 Correct 250 ms 199112 KB Output is correct
21 Correct 224 ms 184676 KB Output is correct
22 Correct 195 ms 197752 KB Output is correct
23 Correct 221 ms 182068 KB Output is correct
24 Correct 221 ms 191816 KB Output is correct
25 Correct 172 ms 180620 KB Output is correct
26 Correct 192 ms 195204 KB Output is correct
27 Correct 191 ms 183928 KB Output is correct
28 Correct 176 ms 183368 KB Output is correct
29 Correct 174 ms 195420 KB Output is correct
30 Correct 156 ms 190104 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Incorrect 4 ms 3408 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3408 KB Output is correct
2 Correct 4 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 4 ms 3408 KB Output is correct
5 Correct 4 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 4 ms 3408 KB Output is correct
9 Correct 4 ms 3408 KB Output is correct
10 Correct 4 ms 3408 KB Output is correct
11 Correct 4 ms 3408 KB Output is correct
12 Correct 4 ms 3548 KB Output is correct
13 Correct 4 ms 3408 KB Output is correct
14 Correct 5 ms 3408 KB Output is correct
15 Correct 4 ms 3408 KB Output is correct
16 Correct 218 ms 190792 KB Output is correct
17 Correct 246 ms 188304 KB Output is correct
18 Correct 188 ms 188744 KB Output is correct
19 Correct 212 ms 191044 KB Output is correct
20 Correct 250 ms 199112 KB Output is correct
21 Correct 224 ms 184676 KB Output is correct
22 Correct 195 ms 197752 KB Output is correct
23 Correct 221 ms 182068 KB Output is correct
24 Correct 221 ms 191816 KB Output is correct
25 Correct 172 ms 180620 KB Output is correct
26 Correct 192 ms 195204 KB Output is correct
27 Correct 191 ms 183928 KB Output is correct
28 Correct 176 ms 183368 KB Output is correct
29 Correct 174 ms 195420 KB Output is correct
30 Correct 156 ms 190104 KB Output is correct
31 Runtime error 20 ms 11080 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -