QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#463772 | #7306. Multi-stage Marathon | hos_lyric | AC ✓ | 234ms | 4280kb | C++14 | 6.6kb | 2024-07-05 14:06:46 | 2024-07-05 14:06:46 |
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 <random>
#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; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
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 = 1000000007;
using Mint = ModInt<MO>;
// det(a + x I)
// O(n^3)
// Call by value: Modifies a (Watch out when using C-style array!)
template <class T> vector<T> charPoly(vector<vector<T>> a) {
const int n = a.size();
// upper Hessenberg
for (int j = 0; j < n - 2; ++j) {
for (int i = j + 1; i < n; ++i) {
if (a[i][j]) {
swap(a[j + 1], a[i]);
for (int ii = 0; ii < n; ++ii) swap(a[ii][j + 1], a[ii][i]);
break;
}
}
if (a[j + 1][j]) {
const T s = 1 / a[j + 1][j];
for (int i = j + 2; i < n; ++i) {
const T t = s * a[i][j];
for (int jj = j; jj < n; ++jj) a[i][jj] -= t * a[j + 1][jj];
for (int ii = 0; ii < n; ++ii) a[ii][j + 1] += t * a[ii][i];
}
}
}
// fss[i] := det(a[0..i][0..i] + x I_i)
vector<vector<T>> fss(n + 1);
fss[0] = {1};
for (int i = 0; i < n; ++i) {
fss[i + 1].assign(i + 2, 0);
for (int k = 0; k <= i; ++k) fss[i + 1][k + 1] = fss[i][k];
for (int k = 0; k <= i; ++k) fss[i + 1][k] += a[i][i] * fss[i][k];
T prod = 1;
for (int j = i - 1; j >= 0; --j) {
prod *= -a[j + 1][j];
const T t = prod * a[j][i];
for (int k = 0; k <= j; ++k) fss[i + 1][k] += t * fss[j][k];
}
}
return fss[n];
}
int N, M, T;
char G[80][80];
vector<int> S, V;
// B[i][u] := (A^i)[u][N-1]
Mint B[80][80];
int main() {
for (; ~scanf("%d%d%d", &N, &M, &T); ) {
for (int u = 0; u < N; ++u) {
scanf("%s", G[u]);
}
S.resize(M);
V.resize(M);
for (int m = 0; m < M; ++m) {
scanf("%d%d", &S[m], &V[m]);
--V[m];
}
vector<vector<Mint>> A(N, vector<Mint>(N, 0));
for (int u = 0; u < N; ++u) {
const int deg = count(G[u], G[u] + N, '1');
const Mint invDeg = Mint(deg).inv();
for (int v = 0; v < N; ++v) if (G[u][v] == '1') A[u][v] = invDeg;
}
for (int i = 0; i <= N; ++i) {
for (int u = 0; u < N; ++u) {
B[i][u] = 0;
}
}
for (int u = 0; u < N; ++u) {
B[0][u] = (u == N-1) ? 1 : 0;
}
for (int i = 0; i < N; ++i) {
for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) {
B[i + 1][u] += A[u][v] * B[i][v];
}
}
auto F = charPoly(A);
for (int i = N - 1; i >= 0; i -= 2) F[i] = -F[i];
// cerr<<"F = "<<F<<endl;
unsigned key = 0;
// (ans[t], ..., ans[t+N-1])
vector<Mint> gs(N + 1, 0);
for (int m = 0, t = 1; t <= T; ++t) {
// advance
for (int i = 0; i < N; ++i) gs[N] -= F[i] * gs[i];
for (int i = 0; i < N; ++i) gs[i] = gs[i + 1];
gs[N] = 0;
// cerr<<"t = "<<t<<": gs = "<<gs<<endl;
// start
for (; m < M && S[m] == t; ++m) {
for (int i = 0; i < N; ++i) {
gs[i] += B[i][V[m]];
}
// cerr<<"m = "<<m<<": gs = "<<gs<<endl;
}
key ^= gs[0].x;
}
printf("%u\n", key);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4088kb
input:
2 2 2 11 11 1 1 2 2
output:
500000005
result:
ok 1 number(s): "500000005"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
3 1 6 110 011 101 1 1
output:
191901811
result:
ok 1 number(s): "191901811"
Test #3:
score: 0
Accepted
time: 3ms
memory: 4204kb
input:
70 1000 10000 1000000000000000000000000000000100000000100000000000000100000000000000 0110000000000001100000100000000000000001000000010000000000000000000000 0010000000000000000000000000000000000000000000000000000000000000000000 0001000000000000000000000000001000000000000000000000000000000000100000 00...
output:
1026871829
result:
ok 1 number(s): "1026871829"
Test #4:
score: 0
Accepted
time: 3ms
memory: 3860kb
input:
70 1000 10000 1000000000000000000000000000000000000000000000000000000001000001010000 0100000000000000000000000000000010000000000000000000000000000000000000 0010000000000000000000010100000001000001000000000000000010000000000000 0001000000000000000010000000000000010000000000000000000000000000000000 00...
output:
743579645
result:
ok 1 number(s): "743579645"
Test #5:
score: 0
Accepted
time: 3ms
memory: 3884kb
input:
70 1000 10000 1100000001000100000000000001110000000000000100000000000001000000000100 0110010000000100000000000100000000100000100000000000000000000000010001 0010000010000000000000000000000000001000000000000000000100010000000000 1001100010100000001000010000000000000001000000000000010000000000001000 00...
output:
362752022
result:
ok 1 number(s): "362752022"
Test #6:
score: 0
Accepted
time: 3ms
memory: 4204kb
input:
70 1000 10000 1010000100000010100001010000100000000010000110110000000000000000001000 0101000010000100001010101010010000000000000000000000001011011010000100 0010001010001100000010010001001001101100010110100010001000000010000000 0101000001100010101010101101000100000101110010000100100010100110000001 00...
output:
69495152
result:
ok 1 number(s): "69495152"
Test #7:
score: 0
Accepted
time: 3ms
memory: 4200kb
input:
70 1000 10000 1110001110101011001011011010000110000110001100010010110011111100001000 1101110110001010001111001101010100001001101010001100101111010011010001 1010011100110110110001001011100110101101111110001100101010100111101110 1001001001000111110100001000001011001000111101111101000001111111110111 00...
output:
976173806
result:
ok 1 number(s): "976173806"
Test #8:
score: 0
Accepted
time: 3ms
memory: 3880kb
input:
70 1000 10000 1111111111011111111100101011001011111101100111111111111111101011011111 1110111111100100101111111101111110111111100111110000101111101101101111 1111110111111110101000110011110111101111110111111111111111011110111011 1111011111001110111110101111111100011101111100110111011111111011001010 11...
output:
407126826
result:
ok 1 number(s): "407126826"
Test #9:
score: 0
Accepted
time: 3ms
memory: 3912kb
input:
70 1000 10000 1111110101111111110111111111111111111101111010110111111111111111011111 1111011111111111111111111011111111111111111111110111111111111111111111 1110110111101100111111011110111111111111101111111111111111111111111111 1111111111111111110111111111111110111111011011111111101111111010011111 01...
output:
95235184
result:
ok 1 number(s): "95235184"
Test #10:
score: 0
Accepted
time: 3ms
memory: 3912kb
input:
70 1000 10000 1111110111110111111111111111111111111111111111101111111111111111101111 1111111011111011111111111111111111111111111111111111111111111111111111 1111111111111111111011111111110111111111111011111111111111011111111111 1111110111111111111111111011101110101111111111111111101111101111111111 11...
output:
137040690
result:
ok 1 number(s): "137040690"
Test #11:
score: 0
Accepted
time: 3ms
memory: 4208kb
input:
70 1000 10000 1111111111111111111111111111111111111111111111111111111111111111111111 1111111101111011111101111111111011111111111111111111111110011111111111 1111111111111111101111111111111110111011111111011111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111111111 11...
output:
918692147
result:
ok 1 number(s): "918692147"
Test #12:
score: 0
Accepted
time: 229ms
memory: 4240kb
input:
70 10000 2000000 1111111111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111111111...
output:
154305482
result:
ok 1 number(s): "154305482"
Test #13:
score: 0
Accepted
time: 234ms
memory: 4056kb
input:
70 10000 2000000 1000010000000000000000000001000000000000000000000000000010000000000000 0100000000000000000000010000000001000010000000000000000000000000000000 0010000000000000000000100000000001001000000000000000000000000000010000 0001000000100000000000000000000000000000000000000000000100000000000000...
output:
601860703
result:
ok 1 number(s): "601860703"
Test #14:
score: 0
Accepted
time: 234ms
memory: 3996kb
input:
70 10000 2000000 1000000000000000010000000001000000000100000000000000001000000000000000 0110000001000000000000000010000000000000000001000001000000000000000000 0010000000110000010010001000000000000000000000101100000000000000000100 0001000000000000010000000000000000000101000100010000000000010010000000...
output:
632681263
result:
ok 1 number(s): "632681263"
Test #15:
score: 0
Accepted
time: 234ms
memory: 4040kb
input:
70 10000 2000000 1000100000100000000000000000000000000001000000011010110000000000100000 1100100010000000000000101000000000000000000000000001000000000000000000 0010000000000001000000000000000001000000000000010000000000000001000000 0001000000001000000000000010100100000000000000000001000100000000001000...
output:
50850594
result:
ok 1 number(s): "50850594"
Test #16:
score: 0
Accepted
time: 233ms
memory: 3976kb
input:
70 10000 2000000 1100000001001000001000100000010000100001000111000001110001100000000100 0110001100000011000001100000001100010100010100010000101100101110001100 0110000100110010001000100000010000010100010000000000000101000101000000 0101000100011010100000000010000010100000011100100000110101001010001100...
output:
117421938
result:
ok 1 number(s): "117421938"
Test #17:
score: 0
Accepted
time: 230ms
memory: 3996kb
input:
70 10000 2000000 1011001110101010010100110110100011001101010001100011111010101111100100 1111000000100001000100100111000011111011110111111000110100101010011010 0011110100101011000000010000100011110100011111001000100010110111110011 0001000111111000001100100110110010110000001010000101110110000000011011...
output:
671321149
result:
ok 1 number(s): "671321149"
Test #18:
score: 0
Accepted
time: 234ms
memory: 4268kb
input:
70 10000 2000000 1111111111101011101101111111011111100111111111001111011100111111110110 0111011001011100111100111111100101101111111101100111100011111111111101 1010111111111110111111111110110110111110111011100111000001111011110100 1111110100101010101111010111101111111111111111111111011101011111101111...
output:
714929330
result:
ok 1 number(s): "714929330"
Test #19:
score: 0
Accepted
time: 233ms
memory: 3980kb
input:
70 10000 2000000 1001111111111111111111111110111111011111111011011111111101111111111111 1110101111011110111111111111111111111111111111110111111111111111110110 1011010110101111111101111111111011111111111110111111100101111111100111 1111111110111111111111100111111100111111101111110101011101111110110111...
output:
706080518
result:
ok 1 number(s): "706080518"
Test #20:
score: 0
Accepted
time: 233ms
memory: 3980kb
input:
70 10000 2000000 1111111111111111111111111111111101111110111111111111111111111111111111 1111110111111111111111111111111111111111111111111111111111101111110111 1111111101111111111111111111111111111111111111111111101011111111111111 1111111111111111111111111111111111111111111111111111111111111111111111...
output:
456121666
result:
ok 1 number(s): "456121666"
Test #21:
score: 0
Accepted
time: 233ms
memory: 4280kb
input:
70 10000 2000000 1111110111111111111111111111111111111111111111111111111111111111111111 1101111111111111111101111111111111111111111110111111111111111110111111 1111111111111111111111111111111111111111111111011111111111111111111111 1111111111111111111111111111111111111111111111111111111110111011111011...
output:
964660092
result:
ok 1 number(s): "964660092"
Extra Test:
score: 0
Extra Test Passed