QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360252#7612. Matrix Inversewillow#WA 740ms35328kbC++174.4kb2024-03-21 16:05:212024-03-21 16:05:21

Judging History

你现在查看的是最新测评结果

  • [2024-03-21 16:05:21]
  • 评测
  • 测评结果:WA
  • 用时:740ms
  • 内存:35328kb
  • [2024-03-21 16:05:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2005;

namespace ModCalculator {
    const int MOD = 1e9 + 7;
    inline void Inc(int &x, int y) {
        x += y; if (x >= MOD) x -= MOD;
    }
    inline int Add(int x, int y) {
        Inc(x, y); return x;
    }
    inline void Dec(int &x, int y) {
        x -= y; if (x < 0) x += MOD;
    }
    inline int Sub(int x, int y) {
        Dec(x, y); return x;
    }
    inline int Mul(int x, int y) {
        return 1LL * x * y % MOD;
    }
    inline int Ksm(int x, int y) {
        int ret = 1;
        for (; y; y >>= 1) {
            if (y & 1) ret = Mul(ret, x);
            x = Mul(x, x);
        }
        return ret;
    }
    inline int Inv(int x) {
        return Ksm(x, MOD - 2);
    }
}
using namespace ModCalculator;

mt19937_64 Rand(998244353);
int n, a[N][N], b[N][N], v[N], v1[N], v2[N];
int wr[N], mr, wc[N], mc, vis[N];
int ma[N][20];
vector< pair<pair<int, int>, int> > ans;

void Gauss() {
    for (int i = 1; i <= mr; ++i) {
        int p = i;
        while (p <= n && ma[p][i] == 0) {
            ++p;
        }
        if (p > i) {
            for (int j = i; j <= mr + 1; ++j) {
                swap(ma[i][j], ma[p][j]);
            }
        }
        int iv = Inv(ma[i][i]);
        for (int j = i; j <= mr + 1; ++j) {
            ma[i][j] = Mul(ma[i][j], iv);
        }
        for (int j = i + 1; j <= n; ++j) {
            int tmp = ma[j][i];
            for (int k = i; k <= mr + 1; ++k) {
                Dec(ma[j][k], Mul(tmp, ma[i][k]));
            }
        }
    }
    for (int i = mr; i >= 1; --i) {
        for (int j = 1; j < i; ++j) {
            Dec(ma[j][n + 1], Mul(ma[j][i], ma[i][n + 1]));
        }
    }
}

void solve() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            scanf("%d", &b[i][j]);
        }
    }

    for (int T = 1; T <= 3; ++T) {
        for (int i = 1; i <= n; ++i) {
            v[i] = Rand() % MOD;
        }
        for (int i = 1; i <= n; ++i) {
            v1[i] = 0;
            for (int j = 1; j <= n; ++j) {
                Inc(v1[i], Mul(v[j], a[j][i]));
            }
        }
        for (int i = 1; i <= n; ++i) {
            v2[i] = 0;
            for (int j = 1; j <= n; ++j) {
                Inc(v2[i], Mul(v1[j], b[j][i]));
            }
        }
        for (int i = 1; i <= n; ++i) {
            if (v2[i] != v[i]) {
                wc[++mc] = i;
            }
        }
        for (int i = 1; i <= n; ++i) {
            v1[i] = 0;
            for (int j = 1; j <= n; ++j) {
                Inc(v1[i], Mul(v[j], a[i][j]));
            }
        }
        for (int i = 1; i <= n; ++i) {
            v2[i] = 0;
            for (int j = 1; j <= n; ++j) {
                Inc(v2[i], Mul(v1[j], b[i][j]));
            }
        }
        for (int i = 1; i <= n; ++i) {
            if (v2[i] != v[i]) {
                wr[++mr] = i;
            }
        }
    }
    sort(wr + 1, wr + mr + 1);
    mr = unique(wr + 1, wr + mr + 1) - (wr + 1);
    sort(wc + 1, wc + mc + 1);
    mc = unique(wc + 1, wc + mc + 1) - (wc + 1);
//for (int i = 1; i <= mr; ++i) cerr << "r " << wr[i] << endl;
//for (int i = 1; i <= mc; ++i) cerr << "c " << wc[i] << endl;
    
    for (int i = 1; i <= mr; ++i) {
        vis[wr[i]] = 1;
    }
    for (int k = 1; k <= mc; ++k) { 
        int c = wc[k];
        for (int i = 1; i <= n; ++i) {
            ma[i][mr + 1] = (i == c);
            for (int j = 1; j <= n; ++j) {
                if (!vis[j]) {
                    Dec(ma[i][mr + 1], Mul(a[i][j], b[j][c]));
                }
            }
            for (int j = 1; j <= mr; ++j) {
                ma[i][j] = a[i][wr[j]];
            }
        }
        Gauss();
        for (int i = 1; i <= mr; ++i) {
            if (ma[i][mr + 1] != b[wr[i]][c]) {
                ans.push_back(make_pair(make_pair(wr[i], c), ma[i][mr + 1]));
            }
        }
    }
    sort(ans.begin(), ans.end());
    printf("%d\n", (int)ans.size());
    for (auto pr : ans) {
        printf("%d %d %d\n", pr.first.first, pr.first.second, pr.second);
    }
}

int main() {
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3840kb

input:

1
953176428
107682094

output:

0

result:

ok single line: '0'

Test #2:

score: -100
Wrong Answer
time: 740ms
memory: 35328kb

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...

output:

3
827 238 196780498
827 499 713564622
1466 499 206940592

result:

wrong answer 1st lines differ - expected: '2', found: '3'