Submission #1044907

# Submission time Handle Problem Language Result Execution time Memory
1044907 2024-08-05T14:27:39 Z PagodePaiva Binaria (CCO23_day1problem1) C++17
25 / 25
157 ms 28848 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6+10;
int pai[N];
int res[N];
const int mod = 1e6 + 3;

int binpow(int a, int b, int m){
    if(b == 0) return 1;
    int t = binpow(a, b/2, m);
    if(b % 2 == 0) return (t*t) % m;
    return (((t*t) % m )*a) % m;
}

int fat(int x){
    if(x < 0) return 0;
    if(x == 0) return 1;
    return (fat(x-1)*x) % mod;
}

int choose(int a, int b){
    swap(a, b);
    return ((fat(a) % mod)*binpow((fat(b)*fat(a-b)) % mod, mod-2, mod)) % mod;
}

int32_t main(){
    int n, k;
    cin >> n >> k;
    vector <int> v;
    for(int i = 1;i <= n-k+1;i++){
        int x;
        cin >> x;
        v.push_back(x);
    }
    for(int i = 1;i < v.size();i++){
        pai[i] = v[i]-v[i-1];
        //cout << pai[i] << ' ';
    }
    // cout << '\n';
    int cnt = 0;
    int val = v[0];
    for(int i = 1;i <= k;i++){
        int at = i;
        res[i] = -1;
        while(at < n){
            if(pai[at] == 0){
                at += k;
            }
            else{
                if(pai[at] == -1){
                    res[i] = 1;
                    break;
                }
                else{
                    res[i] = 0;
                    break;
                }
            }
        }
        if(res[i] == -1) cnt++;
        else val -= res[i];
    }
    // cout << val << endl;
    if(val < 0){
        cout << 0 << endl;
        return 0;
    }
    int resposta = choose(val, cnt);
    for(int i = 1;i <= k;i++){
        if(res[i] == -1 and val > 0){
            val--;
            res[i] = 1;
        }
        else if(val == 0 and res[i] == -1) res[i] = 0;
    }

    int pref = 0;
    for(int i = 1;i <= k;i++){
        pref += res[i];
       // cout << res[i] << ' ';
    } 
    if(pref != v[0]){
        cout << 0 << endl;
        return 0;
    }
    for(int i = k+1;i <= n;i++){
        res[i] = v[i-k] - (pref-res[i-k]);
        pref -= res[i-k];
        pref += res[i];
        if(res[i] != 0 and res[i] != 1){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << resposta << '\n';
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:38:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 1;i < v.size();i++){
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2492 KB Output is correct
27 Correct 0 ms 2492 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2492 KB Output is correct
27 Correct 0 ms 2492 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 81 ms 26032 KB Output is correct
36 Correct 91 ms 26540 KB Output is correct
37 Correct 90 ms 26800 KB Output is correct
38 Correct 90 ms 26852 KB Output is correct
39 Correct 82 ms 25772 KB Output is correct
40 Correct 99 ms 27248 KB Output is correct
41 Correct 157 ms 26800 KB Output is correct
42 Correct 78 ms 25872 KB Output is correct
43 Correct 74 ms 25772 KB Output is correct
44 Correct 74 ms 25772 KB Output is correct
45 Correct 116 ms 25776 KB Output is correct
46 Correct 107 ms 25944 KB Output is correct
47 Correct 72 ms 26152 KB Output is correct
48 Correct 104 ms 26804 KB Output is correct
49 Correct 90 ms 26800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2492 KB Output is correct
27 Correct 0 ms 2492 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 81 ms 26032 KB Output is correct
36 Correct 91 ms 26540 KB Output is correct
37 Correct 90 ms 26800 KB Output is correct
38 Correct 90 ms 26852 KB Output is correct
39 Correct 82 ms 25772 KB Output is correct
40 Correct 99 ms 27248 KB Output is correct
41 Correct 157 ms 26800 KB Output is correct
42 Correct 78 ms 25872 KB Output is correct
43 Correct 74 ms 25772 KB Output is correct
44 Correct 74 ms 25772 KB Output is correct
45 Correct 116 ms 25776 KB Output is correct
46 Correct 107 ms 25944 KB Output is correct
47 Correct 72 ms 26152 KB Output is correct
48 Correct 104 ms 26804 KB Output is correct
49 Correct 90 ms 26800 KB Output is correct
50 Correct 148 ms 28664 KB Output is correct
51 Correct 129 ms 28848 KB Output is correct
52 Correct 122 ms 28844 KB Output is correct
53 Correct 138 ms 28844 KB Output is correct
54 Correct 120 ms 28848 KB Output is correct
55 Correct 122 ms 28848 KB Output is correct
56 Correct 129 ms 28848 KB Output is correct
57 Correct 103 ms 27844 KB Output is correct
58 Correct 125 ms 28688 KB Output is correct
59 Correct 119 ms 28848 KB Output is correct
60 Correct 156 ms 27696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2492 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2492 KB Output is correct
27 Correct 0 ms 2492 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 81 ms 26032 KB Output is correct
36 Correct 91 ms 26540 KB Output is correct
37 Correct 90 ms 26800 KB Output is correct
38 Correct 90 ms 26852 KB Output is correct
39 Correct 82 ms 25772 KB Output is correct
40 Correct 99 ms 27248 KB Output is correct
41 Correct 157 ms 26800 KB Output is correct
42 Correct 78 ms 25872 KB Output is correct
43 Correct 74 ms 25772 KB Output is correct
44 Correct 74 ms 25772 KB Output is correct
45 Correct 116 ms 25776 KB Output is correct
46 Correct 107 ms 25944 KB Output is correct
47 Correct 72 ms 26152 KB Output is correct
48 Correct 104 ms 26804 KB Output is correct
49 Correct 90 ms 26800 KB Output is correct
50 Correct 148 ms 28664 KB Output is correct
51 Correct 129 ms 28848 KB Output is correct
52 Correct 122 ms 28844 KB Output is correct
53 Correct 138 ms 28844 KB Output is correct
54 Correct 120 ms 28848 KB Output is correct
55 Correct 122 ms 28848 KB Output is correct
56 Correct 129 ms 28848 KB Output is correct
57 Correct 103 ms 27844 KB Output is correct
58 Correct 125 ms 28688 KB Output is correct
59 Correct 119 ms 28848 KB Output is correct
60 Correct 156 ms 27696 KB Output is correct
61 Correct 17 ms 18524 KB Output is correct
62 Correct 20 ms 18616 KB Output is correct
63 Correct 17 ms 19096 KB Output is correct
64 Correct 17 ms 19268 KB Output is correct
65 Correct 87 ms 25188 KB Output is correct
66 Correct 65 ms 24244 KB Output is correct
67 Correct 129 ms 28728 KB Output is correct
68 Correct 26 ms 21452 KB Output is correct
69 Correct 17 ms 18524 KB Output is correct
70 Correct 17 ms 18524 KB Output is correct
71 Correct 16 ms 19036 KB Output is correct