답안 #444178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444178 2021-07-13T09:22:44 Z BeanZ Lottery (CEOI18_lot) C++14
100 / 100
1474 ms 8396 KB
// I_Love_LPL 1y0m3d
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 1e4 + 5;
long long mod = 1000007;
const int lim = 4e5 + 5;
const int lg = 20;
const int base = 311;
const long double eps = 1e-6;
ll a[N], dp[N][105], Q[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, l;
    cin >> n >> l;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    ll q;
    cin >> q;
    vector<ll> mem;
    for (int i = 1; i <= q; i++){
        cin >> Q[i];
        mem.push_back(Q[i]);
    }
    sort(mem.begin(), mem.end());
    for (int d = 1; (d + l) <= n; d++){
        ll cost = 0;
        for (int i = 1; i <= l; i++){
            if (a[i] != a[i + d]) cost++;
        }
        ll id = lower_bound(mem.begin(), mem.end(), cost) - mem.begin();
        dp[1][id]++;
        dp[1 + d][id]++;
        for (int i = 2; (i + d + l - 1) <= n; i++){
            if (a[i - 1] != a[i + d - 1]) cost--;
            if (a[i + l - 1] != a[i + d + l - 1]) cost++;
            id = lower_bound(mem.begin(), mem.end(), cost) - mem.begin();
            dp[i][id]++;
            dp[i + d][id]++;
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j < q; j++){
            dp[i][j] += dp[i][j - 1];
        }
    }
    for (int i = 1; i <= q; i++){
        ll idx = lower_bound(mem.begin(), mem.end(), Q[i]) - mem.begin();
        for (int j = 1; (j + l - 1) <= n; j++){
            cout << dp[j][idx] << " ";
        }
        cout << endl;
    }
}
/*
Ans:

Out:
*/

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 21 ms 1160 KB Output is correct
14 Correct 12 ms 1164 KB Output is correct
15 Correct 11 ms 1164 KB Output is correct
16 Correct 20 ms 1228 KB Output is correct
17 Correct 17 ms 1164 KB Output is correct
18 Correct 18 ms 1204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 678 ms 4468 KB Output is correct
2 Correct 918 ms 4480 KB Output is correct
3 Correct 414 ms 4484 KB Output is correct
4 Correct 338 ms 4468 KB Output is correct
5 Correct 140 ms 2512 KB Output is correct
6 Correct 309 ms 4260 KB Output is correct
7 Correct 100 ms 2508 KB Output is correct
8 Correct 189 ms 3396 KB Output is correct
9 Correct 324 ms 4404 KB Output is correct
10 Correct 339 ms 4472 KB Output is correct
11 Correct 24 ms 1144 KB Output is correct
12 Correct 224 ms 3304 KB Output is correct
13 Correct 156 ms 2880 KB Output is correct
14 Correct 168 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 678 ms 4468 KB Output is correct
2 Correct 918 ms 4480 KB Output is correct
3 Correct 414 ms 4484 KB Output is correct
4 Correct 338 ms 4468 KB Output is correct
5 Correct 140 ms 2512 KB Output is correct
6 Correct 309 ms 4260 KB Output is correct
7 Correct 100 ms 2508 KB Output is correct
8 Correct 189 ms 3396 KB Output is correct
9 Correct 324 ms 4404 KB Output is correct
10 Correct 339 ms 4472 KB Output is correct
11 Correct 24 ms 1144 KB Output is correct
12 Correct 224 ms 3304 KB Output is correct
13 Correct 156 ms 2880 KB Output is correct
14 Correct 168 ms 2884 KB Output is correct
15 Correct 455 ms 4332 KB Output is correct
16 Correct 291 ms 4168 KB Output is correct
17 Correct 365 ms 4556 KB Output is correct
18 Correct 343 ms 4504 KB Output is correct
19 Correct 344 ms 4500 KB Output is correct
20 Correct 345 ms 4508 KB Output is correct
21 Correct 362 ms 4520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 21 ms 1160 KB Output is correct
14 Correct 12 ms 1164 KB Output is correct
15 Correct 11 ms 1164 KB Output is correct
16 Correct 20 ms 1228 KB Output is correct
17 Correct 17 ms 1164 KB Output is correct
18 Correct 18 ms 1204 KB Output is correct
19 Correct 678 ms 4468 KB Output is correct
20 Correct 918 ms 4480 KB Output is correct
21 Correct 414 ms 4484 KB Output is correct
22 Correct 338 ms 4468 KB Output is correct
23 Correct 140 ms 2512 KB Output is correct
24 Correct 309 ms 4260 KB Output is correct
25 Correct 100 ms 2508 KB Output is correct
26 Correct 189 ms 3396 KB Output is correct
27 Correct 324 ms 4404 KB Output is correct
28 Correct 339 ms 4472 KB Output is correct
29 Correct 24 ms 1144 KB Output is correct
30 Correct 224 ms 3304 KB Output is correct
31 Correct 156 ms 2880 KB Output is correct
32 Correct 168 ms 2884 KB Output is correct
33 Correct 455 ms 4332 KB Output is correct
34 Correct 291 ms 4168 KB Output is correct
35 Correct 365 ms 4556 KB Output is correct
36 Correct 343 ms 4504 KB Output is correct
37 Correct 344 ms 4500 KB Output is correct
38 Correct 345 ms 4508 KB Output is correct
39 Correct 362 ms 4520 KB Output is correct
40 Correct 1162 ms 5192 KB Output is correct
41 Correct 20 ms 4556 KB Output is correct
42 Correct 504 ms 5212 KB Output is correct
43 Correct 462 ms 4880 KB Output is correct
44 Correct 494 ms 5072 KB Output is correct
45 Correct 1474 ms 8288 KB Output is correct
46 Correct 31 ms 4804 KB Output is correct
47 Correct 747 ms 8396 KB Output is correct
48 Correct 641 ms 6732 KB Output is correct
49 Correct 637 ms 7364 KB Output is correct