QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311801 | #7612. Matrix Inverse | PlentyOfPenalty | RE | 2ms | 10096kb | C++17 | 3.8kb | 2024-01-22 20:08:57 | 2024-01-22 20:08:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> pii;
typedef long long ll;
const int MAXN = 2011, mod = 1e9 + 7;
void Add(int &a, int t) {
a += t;
if (a >= mod) a -= mod;
}
ll Qpow(ll a, ll p) {
ll res = 1;
while (p) {
if (p & 1) res = res * a % mod;
a = a * a % mod, p >>= 1;
}
return res;
}
int a[MAXN][MAXN],fir[15][MAXN], val[15][MAXN],tp[MAXN], b[MAXN][MAXN], rb[MAXN][MAXN], res[MAXN][MAXN];
int f[MAXN][MAXN];
int row[MAXN], col[MAXN], cr, cc;
bool type[MAXN];
void gauss(int a[15][15], int n) {
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j)
if (a[j][i]) {
std::swap(a[i], a[j]);
break;
}
int inv = Qpow(a[i][i], mod - 2);
for (int k = 1; k <= n + 1; ++k)
a[i][k] = ll(a[i][k]) * inv % mod;
for (int j = 1; j <= n; ++j)
if (i != j && a[j][i]) {
int r = a[j][i];
for (int k = i; k <= n + 1; ++k)
a[j][k] = ((a[j][k] - ll(r) * a[i][k]) % mod + mod) % mod;
}
}
}
int eq[15][15];
struct one {
int x, y, v;
};
std::vector<one> ans;
vector<pii> seq;
int main() {
#ifdef popteam
// freopen("I.in", "r", stdin);
#endif
mt19937 rd(std::chrono::steady_clock::now().time_since_epoch().count());
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
cin >> a[i][j];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
cin >> b[i][j], res[i][j] = b[i][j];
for(int x=1;x<15;++x)
{
for(int k=1;k<=n;++k)fir[x][k]=rd()%mod,tp[k]=0;
for(int i=1;i<=n;++i)
for(int k=1;k<=n;++k)
tp[i]=(tp[i]+ll(fir[x][k])*a[k][i])%mod;
for(int k=1;k<=n;++k)val[x][k]=tp[k],tp[k]=0;
for(int i=1;i<=n;++i)
for(int k=1;k<=n;++k)
tp[k]=(tp[k]+ll(val[x][k])*b[k][i])%mod;
for(int k=1;k<=n;++k)val[x][k]=tp[k],tp[k]=0;
}
for (int c = 1; c <= n; ++c) {
bool err = 0;
for(int x=1;x<15;++x)
if(val[x][c]!=fir[x][c])err=1;
if (err) col[++cc] = c; //, printf("Err,c=%d\n", c);
}
assert(cc <= 12);
for(int x=1;x<15;++x)
{
for(int k=1;k<=n;++k)fir[x][k]=rd()%mod,tp[k]=0;
for(int i=1;i<=n;++i)
for(int k=1;k<=n;++k)
tp[i]=(tp[i]+ll(a[i][k])*fir[x][k])%mod;
for(int k=1;k<=n;++k)val[x][k]=tp[k],tp[k]=0;
for(int i=1;i<=n;++i)
for(int k=1;k<=n;++k)
tp[i]=(tp[i]+ll(b[i][k])*val[x][k])%mod;
for(int k=1;k<=n;++k)val[x][k]=tp[k],tp[k]=0;
}
for(int r=1;r<=n;++r)
{
bool err=0;
for(int x=1;x<15;++x)
if(val[x][r]!=fir[x][r])err=1;
if(err)row[++cr]=r,type[r]=1;
}
fprintf(stderr, "cr=%d\n", cr);
//assert(cr <= 12);
for (int w = 1; w <= cc; ++w) {
memset(eq, 0, sizeof eq);
int c = col[w];
for (int i = 1; i <= cr; ++i) {
if (i == c) ++eq[i][cr + 1];
int cur = 0;
for (int r = 1; r <= n; ++r)
if (type[r])
eq[i][++cur] = a[i][r];
else
eq[i][cr + 1] = ((eq[i][cr + 1] - ll(a[i][r]) * b[r][c]) % mod + mod) % mod;
}
gauss(eq, cr);
int cur = 0;
for (int r = 1; r <= n; ++r)
if (type[r]) {
++cur;
if (res[r][c] != eq[cur][cr + 1]) ans.emplace_back(one{r, c, eq[cur][cr + 1]});
}
}
cout << ans.size() << '\n';
for (auto P : ans)
cout << P.x << " " << P.y << " " << P.v << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10096kb
input:
1 953176428 107682094
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Runtime Error
input:
1995 586309310 548144807 578573993 437893403 641164340 712256053 172321263 108058526 768610920 123320669 762746291 856047593 979279376 29067913 309867338 292286426 45124325 239705174 675003623 213743652 620561338 116308277 695369179 669459894 682522334 846995555 159510341 999359657 645579085 7499563...