Submission #70888

# Submission time Handle Problem Language Result Execution time Memory
70888 2018-08-23T15:36:01 Z georgerapeanu Lottery (CEOI18_lot) C++11
100 / 100
2199 ms 8748 KB
#include <iostream>
#include <algorithm>

using namespace std;

int n,l,q;
int v[10005];
pair<int,int> queries[105];
int dp[2][10005];
int inverseeeee[105];
int ans[105][10005];

int brut(int i,int j){
    int ans = 0;
    for(int k = 0;k < l;k++){
        ans += (v[i + k] != v[j + k]);
    }
    return ans;
}


int main() {
   cin >> n >> l;
   for(int i = 1;i <= n;i++){
      cin >> v[i];
   }

   cin >> q;

   for(int i = 1;i <= q;i++){
      cin >> queries[i].first;
      queries[i].second = i;
   }

   sort(queries + 1,queries + 1 + q);

   for(int i = 1;i <= q;i++){
      inverseeeee[queries[i].second] = i;
   }

   for(int j = 2;j <= n - l + 1;j++){
      dp[1][j] = brut(1,j);
      int st = 0,dr = q + 1;
      while(dr - st > 1){
         int mid = (st + dr) / 2;
         if(queries[mid].first < dp[1][j]){
            st = mid;
         }
         else{
            dr = mid;
         }
      }
      if(dr == q + 1){
         continue;
      }
      ans[dr][1]++;
      ans[dr][j]++;
   }

   for(int i = 2,c = 0;i <= n - l + 1;i++,c ^= 1){
      for(int j = i + 1;j <= n - l + 1;j++){
         dp[c][j] = dp[c ^ 1][j - 1] - (v[i - 1] != v[j - 1]) + (v[i + l - 1] != v[j + l - 1]);
         int st = 0,dr = q + 1;
         while(dr - st > 1){
            int mid = (st + dr) / 2;
            if(queries[mid].first < dp[c][j]){
               st = mid;
            }
            else{
               dr = mid;
            }
         }
         if(dr == q + 1){
            continue;
         }
         ans[dr][i]++;
         ans[dr][j]++;
      }
   }

  for(int i = 1;i <= q;i++){
      for(int j = 1;j <= n - l + 1;j++){
         ans[i][j] += ans[i - 1][j];
      }
   }

   for(int i = 1;i <= q;i++){
      for(int j = 1;j <= n - l + 1;j++){
         cout << ans[inverseeeee[i]][j] << " ";
      }
      cout << "\n";
   }

   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 4 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 4 ms 716 KB Output is correct
11 Correct 4 ms 776 KB Output is correct
12 Correct 4 ms 908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 4 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 4 ms 716 KB Output is correct
11 Correct 4 ms 776 KB Output is correct
12 Correct 4 ms 908 KB Output is correct
13 Correct 39 ms 908 KB Output is correct
14 Correct 24 ms 932 KB Output is correct
15 Correct 28 ms 932 KB Output is correct
16 Correct 40 ms 936 KB Output is correct
17 Correct 36 ms 936 KB Output is correct
18 Correct 33 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 369 ms 936 KB Output is correct
2 Correct 280 ms 936 KB Output is correct
3 Correct 267 ms 936 KB Output is correct
4 Correct 288 ms 936 KB Output is correct
5 Correct 103 ms 936 KB Output is correct
6 Correct 282 ms 936 KB Output is correct
7 Correct 134 ms 936 KB Output is correct
8 Correct 183 ms 936 KB Output is correct
9 Correct 315 ms 936 KB Output is correct
10 Correct 302 ms 936 KB Output is correct
11 Correct 16 ms 936 KB Output is correct
12 Correct 161 ms 936 KB Output is correct
13 Correct 143 ms 936 KB Output is correct
14 Correct 130 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 369 ms 936 KB Output is correct
2 Correct 280 ms 936 KB Output is correct
3 Correct 267 ms 936 KB Output is correct
4 Correct 288 ms 936 KB Output is correct
5 Correct 103 ms 936 KB Output is correct
6 Correct 282 ms 936 KB Output is correct
7 Correct 134 ms 936 KB Output is correct
8 Correct 183 ms 936 KB Output is correct
9 Correct 315 ms 936 KB Output is correct
10 Correct 302 ms 936 KB Output is correct
11 Correct 16 ms 936 KB Output is correct
12 Correct 161 ms 936 KB Output is correct
13 Correct 143 ms 936 KB Output is correct
14 Correct 130 ms 936 KB Output is correct
15 Correct 610 ms 936 KB Output is correct
16 Correct 260 ms 940 KB Output is correct
17 Correct 302 ms 940 KB Output is correct
18 Correct 291 ms 940 KB Output is correct
19 Correct 236 ms 940 KB Output is correct
20 Correct 265 ms 952 KB Output is correct
21 Correct 283 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 4 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 4 ms 716 KB Output is correct
11 Correct 4 ms 776 KB Output is correct
12 Correct 4 ms 908 KB Output is correct
13 Correct 39 ms 908 KB Output is correct
14 Correct 24 ms 932 KB Output is correct
15 Correct 28 ms 932 KB Output is correct
16 Correct 40 ms 936 KB Output is correct
17 Correct 36 ms 936 KB Output is correct
18 Correct 33 ms 936 KB Output is correct
19 Correct 369 ms 936 KB Output is correct
20 Correct 280 ms 936 KB Output is correct
21 Correct 267 ms 936 KB Output is correct
22 Correct 288 ms 936 KB Output is correct
23 Correct 103 ms 936 KB Output is correct
24 Correct 282 ms 936 KB Output is correct
25 Correct 134 ms 936 KB Output is correct
26 Correct 183 ms 936 KB Output is correct
27 Correct 315 ms 936 KB Output is correct
28 Correct 302 ms 936 KB Output is correct
29 Correct 16 ms 936 KB Output is correct
30 Correct 161 ms 936 KB Output is correct
31 Correct 143 ms 936 KB Output is correct
32 Correct 130 ms 936 KB Output is correct
33 Correct 610 ms 936 KB Output is correct
34 Correct 260 ms 940 KB Output is correct
35 Correct 302 ms 940 KB Output is correct
36 Correct 291 ms 940 KB Output is correct
37 Correct 236 ms 940 KB Output is correct
38 Correct 265 ms 952 KB Output is correct
39 Correct 283 ms 1052 KB Output is correct
40 Correct 1185 ms 2308 KB Output is correct
41 Correct 33 ms 2308 KB Output is correct
42 Correct 939 ms 2348 KB Output is correct
43 Correct 891 ms 2348 KB Output is correct
44 Correct 941 ms 2348 KB Output is correct
45 Correct 2199 ms 8620 KB Output is correct
46 Correct 55 ms 8620 KB Output is correct
47 Correct 1838 ms 8748 KB Output is correct
48 Correct 1442 ms 8748 KB Output is correct
49 Correct 1410 ms 8748 KB Output is correct