Submission #683401

# Submission time Handle Problem Language Result Execution time Memory
683401 2023-01-18T10:23:42 Z nifeshe Energetic turtle (IZhO11_turtle) C++17
40 / 100
262 ms 110764 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC target ("avx2")
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma comment (linker, "/STACK: 16777216")

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define int long long

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

ll mod = 998244353;
const ll base = 1e6 + 5;
const ll inf = 1e18;
const int MAX = 3e3;
const int lg = 20;

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<ll> dis(1, inf);

void add(int &a, int b) {
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
}

int C[MAX][MAX];

void solve() {
    int n, m, k, t;
    cin >> n >> m >> k >> t >> mod;
    for(int i = 0; i < MAX; i++) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; j++) {
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
        }
    }
    vector<pair<int, int>> a(k);
    for(auto &[x, y] : a) {
        cin >> x >> y;
    }
    sort(all(a));
    int ans = 0;
    vector<int> ways((1 << k));
    for(int mask = 0; mask < (1 << k); mask++) {
        vector<pair<int, int>> need = {{0, 0}};
        for(int i = 0; i < k; i++) {
            if(mask >> i & 1) {
                need.pb(a[i]);
            }
        }
        need.pb({n, m});
        int sz = sz(need);
        int add = 1;
        for(int i = 1; i < sz; i++) {
            if(need[i - 1].s > need[i].s) {
                add = 0;
                break;
            }
            int x = need[i].f - need[i - 1].f, y = need[i].s - need[i - 1].s;
            add = (add * C[x + y][y]) % mod;
        }
        int sign = (__builtin_popcount(mask) & 1? -1 : 1);
        ways[mask] = sign * add;
    }
    for(int i = 0; i < k; i++) {
        for(int mask = 0; mask < (1 << k); mask++) {
            if(mask >> i & 1) continue;
            add(ways[mask], ways[mask | (1 << i)]);
        }
    }
    for(int mask = 0; mask < (1 << k); mask++) {
        int sign = (__builtin_popcount(mask) & 1? -1 : 1);
        ways[mask] *= sign;
    }
    for(int mask = 0; mask < (1 << k); mask++) {
        if(__builtin_popcount(mask) > t) continue;
        int sign = (__builtin_popcount(mask) & 1? -1 : 1);
        add(ans, ways[mask]);
    }
    cout << ans << '\n';
}

signed main() {
//    freopen("kthpath.in", "r", stdin); freopen("kthpath.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ttt = 1;
//    cin >> ttt;
    while(ttt--) {
        solve();
    }
    return 0;
}

Compilation message

turtle.cpp: In function 'void solve()':
turtle.cpp:96:13: warning: unused variable 'sign' [-Wunused-variable]
   96 |         int sign = (__builtin_popcount(mask) & 1? -1 : 1);
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 46520 KB Output is correct
2 Correct 37 ms 46448 KB Output is correct
3 Correct 42 ms 46380 KB Output is correct
4 Correct 52 ms 46708 KB Output is correct
5 Correct 262 ms 54724 KB Output is correct
6 Correct 38 ms 46440 KB Output is correct
7 Correct 52 ms 46916 KB Output is correct
8 Correct 38 ms 46444 KB Output is correct
9 Runtime error 96 ms 98300 KB Execution killed with signal 11
10 Runtime error 100 ms 102380 KB Execution killed with signal 11
11 Runtime error 104 ms 95164 KB Execution killed with signal 11
12 Runtime error 98 ms 102352 KB Execution killed with signal 11
13 Runtime error 93 ms 94160 KB Execution killed with signal 11
14 Runtime error 97 ms 96204 KB Execution killed with signal 11
15 Runtime error 106 ms 110688 KB Execution killed with signal 11
16 Runtime error 108 ms 110764 KB Execution killed with signal 11
17 Runtime error 101 ms 98220 KB Execution killed with signal 11
18 Runtime error 103 ms 110740 KB Execution killed with signal 11
19 Runtime error 111 ms 110688 KB Execution killed with signal 11
20 Runtime error 107 ms 110684 KB Execution killed with signal 11