Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: C - Shuffle Permutation
- // Contest: AtCoder - AtCoder Regular Contest 107
- // URL: https://atcoder.jp/contests/arc107/tasks/arc107_c
- // Memory Limit: 1024 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- #include <atcoder/dsu>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using vi = vector<int>;
- using ll = long long;
- using pii = pair<int, int>;
- using atcoder::dsu;
- int main(int argc, char **argv)
- {
- int n, k;
- cin >> n >> k;
- auto a = vv<int>(n);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- cin >> a[i][j];
- const int mod = 998244353;
- auto col_op = [&a, k, n](int c1, int c2) {
- bool ret = true;
- for (int i = 0; i < n; ++i)
- if (a[i][c1] + a[i][c2] > k)
- ret = false;
- return ret;
- };
- auto row_op = [&a, k, n](int r1, int r2) {
- bool ret = true;
- for (int i = 0; i < n; ++i)
- if (a[r1][i] + a[r2][i] > k)
- ret = false;
- return ret;
- };
- ll ans = 1;
- auto calc = [&](const function<bool(int, int)> &op) {
- dsu d(n);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < i; ++j)
- if (op(i, j)) {
- d.merge(i, j);
- }
- for (const auto &g : d.groups()) {
- for (int x = g.size(); x > 1; --x)
- ans = ans * x % mod;
- }
- };
- calc(col_op);
- calc(row_op);
- cout << ans << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement