Submission #966922

# Submission time Handle Problem Language Result Execution time Memory
966922 2024-04-20T15:54:37 Z Charizard2021 Lottery (CEOI18_lot) C++17
65 / 100
1308 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
const int MOD = 1e9 + 21;
const int MODInverse = 928571448;
int main(){
    int n, l;
    cin >> n >> l;
    long long powers[1 + n];
    powers[0] = 1;
    long long invPowers[1 + n];
    invPowers[0] = 1;
    for(int i = 1; i <= n; i++){
        powers[i] = powers[i - 1] * p % MOD;
        invPowers[i] = invPowers[i - 1] * MODInverse % MOD;
    }
    vector<int> a(1 + n);
    vector<long long> hashing(1 + n, 0);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        hashing[i] = (hashing[i - 1] + powers[i] * a[i]) % MOD;
    }
    int q;
    cin >> q;
    if(n <= 2000){
        vector<vector<int> > ans(1 + n, vector<int>(1 + n, 0));
        for(int i = 1; i + l - 1 <= n; i++){
            for(int j = i + 1; j + l - 1 <= n; j++){
                for(int k = 0; k < l; k++){
                    if(a[i + k] != a[j + k]){
                        ans[i][j]++;
                        ans[j][i]++;
                    }
                }
            }
        }
        while(q--){
            int val;
            cin >> val;
            for(int i = 1; i + l - 1 <= n; i++){
                int ans2 =0 ;
                for(int j = 1; j + l - 1 <= n; j++){
                    if(i != j){
                        if(ans[i][j] <= val){
                            ans2++;
                        }
                    }
                }
                cout << ans2 << " ";
            }
            cout << "\n";
        }
    }
    else if(q == 1){
        int k;
        cin >> k;
        if(k == 0){
            map<long long, int> freq;
            for(int i = 1; i + l - 1 <= n; i++){
                long long num = hashing[i + l - 1] - hashing[i - 1];
                num %= MOD;
                if(num < 0){
                    num += MOD;
                }
                num = (num * invPowers[i]) % MOD;
                freq[num]++;
            }
            for(int i = 1; i + l - 1 <= n; i++){
                long long num = hashing[i + l - 1] - hashing[i - 1];
                num %= MOD;
                if(num < 0){
                    num += MOD;
                }
                num = (num * invPowers[i]) % MOD;
                cout << freq[num] - 1 << " ";
            }
            cout << "\n";
        }
        else{
            vector<vector<int> > ans(1 + n, vector<int>(1 + n, 0));
            for(int i = 1; i + l - 1 <= n; i++){
                for(int j = i + 1; j + l - 1 <= n; j++){
                    for(int k = 0; k < l; k++){
                        if(a[i + k] != a[j + k]){
                            ans[i][j]++;
                            ans[j][i]++;
                        }
                    }
                }
            }
            while(q--){
                int val;
                cin >> val;
                for(int i = 1; i + l - 1 <= n; i++){
                    int ans2 =0 ;
                    for(int j = 1; j + l - 1 <= n; j++){
                        if(i != j){
                            if(ans[i][j] <= val){
                                ans2++;
                            }
                        }
                    }
                    cout << ans2 << " ";
                }
                cout << "\n";
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 812 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 812 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 44 ms 16220 KB Output is correct
14 Correct 1308 ms 16468 KB Output is correct
15 Correct 1280 ms 16216 KB Output is correct
16 Correct 787 ms 16464 KB Output is correct
17 Correct 1033 ms 16220 KB Output is correct
18 Correct 1036 ms 16228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 5 ms 956 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 5 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 5 ms 956 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 5 ms 996 KB Output is correct
15 Runtime error 30 ms 65536 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 812 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 44 ms 16220 KB Output is correct
14 Correct 1308 ms 16468 KB Output is correct
15 Correct 1280 ms 16216 KB Output is correct
16 Correct 787 ms 16464 KB Output is correct
17 Correct 1033 ms 16220 KB Output is correct
18 Correct 1036 ms 16228 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 4 ms 600 KB Output is correct
22 Correct 5 ms 860 KB Output is correct
23 Correct 5 ms 956 KB Output is correct
24 Correct 6 ms 1116 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 4 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 6 ms 1116 KB Output is correct
31 Correct 5 ms 856 KB Output is correct
32 Correct 5 ms 996 KB Output is correct
33 Runtime error 30 ms 65536 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -