QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149522 | #1786. 路径交点 | hos_lyric | 100 ✓ | 120ms | 9580kb | C++14 | 5.4kb | 2023-08-24 19:41:40 | 2023-08-24 19:41:41 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
Mint det(vector<vector<Mint>> a) {
const int n = a.size();
Mint ret = 1;
for (int h = 0; h < n; ++h) {
for (int i = h; i < n; ++i) if (a[i][h]) {
if (h != i) {
swap(a[h], a[i]);
ret = -ret;
}
break;
}
ret *= a[h][h];
if (!ret) break;
const Mint s = a[h][h].inv();
for (int j = h + 1; j < n; ++j) a[h][j] *= s;
for (int i = h + 1; i < n; ++i) {
const Mint t = a[i][h];
if (t) for (int j = h + 1; j < n; ++j) a[i][j] -= t * a[h][j];
}
}
return ret;
}
int K;
vector<int> N, M;
vector<vector<int>> A, B;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &K);
N.resize(K);
for (int k = 0; k < K; ++k) {
scanf("%d", &N[k]);
}
M.resize(K - 1);
for (int k = 0; k < K - 1; ++k) {
scanf("%d", &M[k]);
}
A.resize(K - 1);
B.resize(K - 1);
for (int k = 0; k < K - 1; ++k) {
A[k].resize(M[k]);
B[k].resize(M[k]);
for (int i = 0; i < M[k]; ++i) {
scanf("%d%d", &A[k][i], &B[k][i]);
--A[k][i];
--B[k][i];
}
}
vector<vector<Mint>> a(N[0], vector<Mint>(N[K - 1]));
for (int s = 0; s < N[0]; ++s) {
vector<Mint> crt(N[0], 0);
crt[s] = 1;
for (int k = 0; k < K - 1; ++k) {
vector<Mint> nxt(N[k + 1], 0);
for (int i = 0; i < M[k]; ++i) {
nxt[B[k][i]] += crt[A[k][i]];
}
crt.swap(nxt);
}
for (int t = 0; t < N[K - 1]; ++t) {
a[s][t] = crt[t];
}
}
const Mint ans = det(a);
printf("%u\n", ans.x);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3760kb
input:
5 2 10 10 49 1 1 1 2 1 7 1 9 2 3 2 6 2 9 2 10 3 1 3 2 3 3 3 5 3 6 3 7 3 8 3 9 4 2 4 3 4 4 4 7 4 10 5 3 5 7 5 10 6 1 6 2 6 3 6 5 6 8 6 9 7 1 7 3 7 8 7 9 7 10 8 5 8 6 8 7 8 9 9 1 9 3 9 4 9 7 9 10 10 2 10 4 10 6 10 9 10 10 2 10 10 46 1 1 1 2 1 3 1 10 2 1 2 2 2 5 2 9 2 10 3 3 3 7 3 8 4 2 4 5 4 7 4 8 4 1...
output:
998244348 24 21 998244346 6
result:
ok 5 lines
Test #2:
score: 5
Accepted
time: 2ms
memory: 3780kb
input:
5 2 10 10 56 1 1 1 3 1 5 1 7 1 9 1 10 2 4 2 5 2 6 2 7 2 8 2 9 2 10 3 1 3 3 3 4 3 6 3 8 3 9 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 9 4 10 5 1 5 2 5 5 5 6 5 7 5 10 6 1 6 4 6 5 6 7 7 1 7 3 7 4 8 3 8 4 8 8 9 2 9 3 9 7 9 8 9 10 10 1 10 2 10 6 10 7 10 8 10 9 10 10 2 10 10 48 1 2 1 4 1 5 1 7 1 8 1 9 1 10 2 1 2 3 2 ...
output:
998244350 1 998244334 998244347 998244348
result:
ok 5 lines
Test #3:
score: 5
Accepted
time: 2ms
memory: 4028kb
input:
5 2 10 10 55 1 5 1 6 2 1 2 3 2 4 2 6 2 7 2 8 2 9 2 10 3 3 3 4 3 5 3 6 3 7 3 10 4 1 4 2 4 3 4 4 4 6 4 7 4 8 4 10 5 1 5 2 5 3 5 5 5 7 6 1 6 2 6 4 6 6 7 3 7 5 7 8 7 9 8 1 8 2 8 4 8 6 8 9 8 10 9 1 9 2 9 4 9 6 9 7 10 2 10 3 10 4 10 6 10 8 10 9 10 10 2 10 10 53 1 1 1 4 1 6 1 10 2 1 2 3 2 4 2 6 2 7 2 8 2 9...
output:
5 998244349 1 1 1
result:
ok 5 lines
Test #4:
score: 5
Accepted
time: 2ms
memory: 3744kb
input:
5 2 10 10 53 1 1 1 2 1 5 1 6 1 7 1 10 2 2 2 3 2 8 3 2 3 3 3 5 3 9 3 10 4 1 4 5 4 6 4 7 4 8 4 9 5 1 5 2 5 3 5 5 5 7 5 10 6 5 6 7 6 8 6 9 6 10 7 4 7 6 7 8 7 9 7 10 8 1 8 2 8 5 8 9 9 1 9 2 9 4 9 5 9 10 10 1 10 2 10 3 10 4 10 6 10 7 10 9 10 10 2 10 10 50 1 1 1 4 1 8 1 10 2 3 2 4 2 5 2 7 2 10 3 2 3 3 3 4...
output:
998244343 998244352 998244347 998244343 998244343
result:
ok 5 lines
Test #5:
score: 5
Accepted
time: 2ms
memory: 3764kb
input:
5 10 10 10 10 10 10 10 10 10 10 10 13 10 18 15 18 18 15 14 13 5 4 4 7 9 6 8 9 10 2 2 1 7 8 3 5 6 10 1 3 2 4 5 8 3 8 4 7 7 8 6 10 9 1 2 2 1 4 8 6 5 9 10 3 3 5 7 9 8 2 10 10 1 1 2 4 4 8 6 7 9 5 3 6 5 3 1 4 5 2 10 7 4 10 4 6 2 10 4 2 1 5 9 5 2 6 10 3 1 10 4 2 8 4 7 1 5 8 6 7 3 9 1 9 8 3 5 6 1 4 9 8 5 8...
output:
1 998244352 1 0 998244352
result:
ok 5 lines
Test #6:
score: 5
Accepted
time: 2ms
memory: 3748kb
input:
5 10 10 10 10 10 10 10 10 10 10 10 16 16 14 17 10 12 15 16 13 5 8 1 10 7 2 9 1 6 4 2 7 8 6 3 3 4 9 10 5 5 4 9 6 7 5 1 1 3 5 1 2 8 7 10 6 2 9 1 5 4 3 7 8 6 4 3 10 9 2 5 1 10 5 2 7 4 8 3 3 3 1 4 2 7 7 6 6 9 10 5 5 3 2 8 1 4 3 10 4 2 9 1 8 1 9 4 10 9 2 10 8 7 3 6 10 10 5 5 1 2 4 1 2 3 6 4 8 9 7 8 9 6 9...
output:
1 1 998244352 0 998244352
result:
ok 5 lines
Test #7:
score: 5
Accepted
time: 2ms
memory: 3752kb
input:
5 10 10 10 10 10 10 10 10 10 10 10 55 49 52 51 47 48 58 49 39 1 1 1 3 1 9 2 2 2 3 2 7 2 8 2 10 3 1 3 2 3 3 3 4 3 5 3 6 3 8 4 1 4 2 4 3 4 5 4 7 4 9 4 10 5 6 5 9 5 10 6 1 6 5 6 6 6 7 6 9 6 10 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 10 8 3 8 4 8 5 8 6 8 7 8 8 8 9 8 10 9 7 9 8 9 9 10 1 10 2 10 3 10 4 10 5 1 1 1 3...
output:
25344 19440 997437953 46080 997544513
result:
ok 5 lines
Test #8:
score: 5
Accepted
time: 1ms
memory: 3756kb
input:
5 10 10 10 10 10 10 10 10 10 10 10 43 48 45 52 50 52 52 46 54 1 1 1 3 1 5 1 6 1 9 1 10 2 1 2 2 2 3 2 5 2 6 2 7 3 5 3 7 3 8 4 3 4 4 4 5 4 7 4 9 5 1 5 2 5 5 5 7 5 10 6 2 6 3 6 6 6 8 7 10 8 1 8 2 8 3 8 6 8 9 9 1 9 4 9 5 9 9 10 1 10 6 10 7 10 8 1 1 1 2 1 4 1 7 2 1 2 2 2 7 2 8 2 9 3 2 3 3 3 4 3 5 3 6 3 8...
output:
998237441 998050817 1920 138240 998239553
result:
ok 5 lines
Test #9:
score: 5
Accepted
time: 2ms
memory: 3748kb
input:
5 10 10 13 10 13 10 10 12 11 11 10 58 62 62 64 49 55 62 57 51 1 2 1 5 1 6 1 9 2 7 2 10 2 11 2 12 2 13 3 4 3 5 3 8 3 9 3 11 3 12 4 2 4 3 4 7 4 11 4 12 5 2 5 4 5 6 5 7 5 8 5 10 5 11 5 13 6 4 6 5 6 6 6 7 6 8 6 10 6 11 6 12 7 2 7 4 7 6 7 8 7 9 7 12 7 13 8 1 8 2 8 6 8 7 8 9 8 10 8 12 9 4 9 6 9 8 9 13 10 ...
output:
0 431535363 869602600 0 462374665
result:
ok 5 lines
Test #10:
score: 5
Accepted
time: 2ms
memory: 4000kb
input:
5 10 10 14 11 10 10 13 10 13 10 10 66 75 55 45 66 53 60 66 56 1 1 1 5 1 7 1 9 2 2 2 5 2 6 2 10 2 12 3 1 3 6 3 7 3 12 3 14 4 3 4 4 4 5 4 7 4 10 4 12 4 13 4 14 5 3 5 5 5 11 5 12 5 13 5 14 6 3 6 4 6 6 6 8 6 9 6 13 6 14 7 1 7 3 7 4 7 6 7 7 7 9 7 12 7 13 7 14 8 1 8 2 8 3 8 7 8 8 8 9 8 10 8 11 8 12 9 1 9 ...
output:
509445037 210531260 116561285 0 480038571
result:
ok 5 lines
Test #11:
score: 5
Accepted
time: 2ms
memory: 3876kb
input:
5 2 10 10 56 1 1 1 2 1 3 1 5 1 6 1 7 1 9 2 1 2 3 2 5 2 7 2 9 3 2 3 3 3 4 3 8 3 10 4 1 4 2 4 5 4 6 5 1 5 2 5 3 5 4 5 7 5 8 5 10 6 1 6 2 6 3 6 7 7 1 7 3 7 4 7 5 7 6 7 7 7 8 8 1 8 2 8 3 8 4 8 5 8 7 9 2 9 4 9 8 9 9 10 1 10 2 10 3 10 4 10 7 10 9 10 10 2 10 10 46 1 1 1 2 1 3 1 5 1 7 1 9 2 2 2 7 2 8 2 9 3 ...
output:
998244347 7 547857492 998244348 998244349
result:
ok 5 lines
Test #12:
score: 5
Accepted
time: 1ms
memory: 4156kb
input:
5 2 10 10 42 1 1 1 4 1 5 1 7 1 8 2 1 2 2 2 8 3 1 3 5 3 6 3 8 4 3 4 5 5 1 5 3 5 4 5 7 5 9 5 10 6 2 6 6 6 8 7 1 7 3 7 4 7 10 8 3 8 4 8 8 8 10 9 3 9 5 9 7 9 8 9 10 10 2 10 4 10 5 10 6 10 8 10 9 2 100 100 4905 1 1 1 2 1 5 1 6 1 7 1 10 1 13 1 14 1 15 1 17 1 18 1 20 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 32...
output:
998244341 530973746 2 0 1
result:
ok 5 lines
Test #13:
score: 5
Accepted
time: 1ms
memory: 3868kb
input:
5 2 10 10 58 1 1 1 2 1 4 1 9 1 10 2 2 2 3 2 6 2 7 2 8 3 3 3 6 3 7 3 8 3 9 3 10 4 1 4 2 4 5 4 6 4 7 4 8 5 1 5 2 5 3 5 4 5 5 5 7 5 8 5 9 5 10 6 1 6 2 6 5 6 6 6 7 6 9 7 3 7 4 7 5 7 6 7 7 7 8 7 10 8 1 8 4 8 5 8 9 8 10 9 2 9 5 9 8 9 9 9 10 10 2 10 6 10 7 10 8 2 10 10 55 1 1 1 5 1 7 1 8 1 10 2 1 2 2 2 4 2...
output:
3 998244351 998244348 2 741330205
result:
ok 5 lines
Test #14:
score: 5
Accepted
time: 5ms
memory: 4020kb
input:
5 100 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
1 998244352 1 0 1
result:
ok 5 lines
Test #15:
score: 5
Accepted
time: 2ms
memory: 3932kb
input:
5 100 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
0 1 998244352 1 998244352
result:
ok 5 lines
Test #16:
score: 5
Accepted
time: 70ms
memory: 7820kb
input:
5 100 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
334543195 834743238 64906936 887345970 749415036
result:
ok 5 lines
Test #17:
score: 5
Accepted
time: 81ms
memory: 7980kb
input:
5 100 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
551005664 774916190 258165927 333831611 45511363
result:
ok 5 lines
Test #18:
score: 5
Accepted
time: 120ms
memory: 9580kb
input:
5 100 10 15 13 13 12 13 13 13 10 13 11 11 11 12 11 12 13 11 12 13 10 10 10 11 11 12 12 10 10 10 11 10 12 12 10 13 12 12 12 11 10 12 13 12 13 13 12 10 10 11 10 12 10 10 10 12 11 12 12 10 12 12 11 15 13 12 10 11 12 12 10 11 11 10 10 12 11 12 13 13 10 13 13 13 10 11 11 11 12 10 11 13 10 12 10 10 13 11 ...
output:
0 131476393 674791629 0 453887582
result:
ok 5 lines
Test #19:
score: 5
Accepted
time: 114ms
memory: 9444kb
input:
5 100 10 12 10 13 10 12 13 12 12 13 10 11 13 12 13 12 10 12 13 12 10 12 12 12 10 10 13 12 10 10 13 11 10 12 11 12 10 10 13 11 11 11 12 10 11 11 11 13 13 13 13 11 11 12 10 10 13 13 10 11 13 11 11 15 10 10 13 11 12 12 13 10 11 13 12 13 11 10 11 10 13 13 10 10 13 11 13 13 10 13 12 13 13 11 13 11 11 12 ...
output:
0 654380406 500344548 0 452282079
result:
ok 5 lines
Test #20:
score: 5
Accepted
time: 113ms
memory: 9480kb
input:
5 100 100 119 112 115 121 120 115 112 137 116 150 123 115 113 112 113 130 118 104 127 103 122 123 118 116 139 102 117 137 111 131 135 106 119 135 106 119 103 115 124 123 135 135 122 134 117 106 128 115 121 115 115 131 112 124 135 120 113 174 113 106 115 101 124 101 117 126 130 113 105 124 139 129 12...
output:
50989987 555456312 817057040 0 277357563
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed