Advertisement
pb_jiang

ARC107C

Nov 28th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. // Problem: C - Shuffle Permutation
  2. // Contest: AtCoder - AtCoder Regular Contest 107
  3. // URL: https://atcoder.jp/contests/arc107/tasks/arc107_c
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. #include <atcoder/dsu>
  12.  
  13. using namespace std;
  14. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  15. template <typename... Args> void logger(string vars, Args &&... values)
  16. {
  17.     cerr << vars << " = ";
  18.     string delim = "";
  19.     (..., (cerr << delim << values, delim = ", "));
  20.     cerr << endl;
  21. }
  22.  
  23. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  24. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  25. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  26. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  27.  
  28. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  29. using vi = vector<int>;
  30. using ll = long long;
  31. using pii = pair<int, int>;
  32. using atcoder::dsu;
  33.  
  34. int main(int argc, char **argv)
  35. {
  36.     int n, k;
  37.     cin >> n >> k;
  38.     auto a = vv<int>(n);
  39.     for (int i = 0; i < n; ++i)
  40.         for (int j = 0; j < n; ++j)
  41.             cin >> a[i][j];
  42.     const int mod = 998244353;
  43.     auto col_op = [&a, k, n](int c1, int c2) {
  44.         bool ret = true;
  45.         for (int i = 0; i < n; ++i)
  46.             if (a[i][c1] + a[i][c2] > k)
  47.                 ret = false;
  48.         return ret;
  49.     };
  50.     auto row_op = [&a, k, n](int r1, int r2) {
  51.         bool ret = true;
  52.         for (int i = 0; i < n; ++i)
  53.             if (a[r1][i] + a[r2][i] > k)
  54.                 ret = false;
  55.         return ret;
  56.     };
  57.     ll ans = 1;
  58.     auto calc = [&](const function<bool(int, int)> &op) {
  59.         dsu d(n);
  60.         for (int i = 0; i < n; ++i)
  61.             for (int j = 0; j < i; ++j)
  62.                 if (op(i, j)) {
  63.                     d.merge(i, j);
  64.                 }
  65.         for (const auto &g : d.groups()) {
  66.             for (int x = g.size(); x > 1; --x)
  67.                 ans = ans * x % mod;
  68.         }
  69.     };
  70.     calc(col_op);
  71.     calc(row_op);
  72.     cout << ans << endl;
  73.     return 0;
  74. };
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement