QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#369287#7612. Matrix InverseDelay_for_five_minutes#WA 632ms36052kbC++204.4kb2024-03-27 23:04:072024-03-27 23:04:09

Judging History

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

  • [2024-03-27 23:04:09]
  • 评测
  • 测评结果:WA
  • 用时:632ms
  • 内存:36052kb
  • [2024-03-27 23:04:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int a[2005][2005];
int a2[2005][2005];
int n;
const int T = 3;
bool ok[2005];

int I[2005];
const int mod = 1e9 + 7;
typedef pair<int,int> pii;
mt19937 rnd(0);

int AI[2005];
int AI2[2005];
void test() {
    for(int i = 1;i <= n;i++) I[i] = rnd()%(mod - 1) + 1;
    for(int i = 1;i <= n;i++) { //[i,1]
        AI[i] = 0;
        for(int j = 1;j <= n;j++) { //A[i][j]
            AI[i] = (AI[i] + 1LL * a[i][j] * I[j]) % mod;
        }
    }
    for(int i = 1;i <= n;i++) {
        AI2[i] = 0;
        for(int j = 1;j <= n;j++) {
            AI2[i] = (AI2[i] + 1LL * a2[i][j] * AI[j]) % mod;
        }
        AI2[i] = (I[i] - AI2[i] + mod) % mod;
    }
    for(int i = 1;i <= n;i++) {
        if(AI2[i] != 0) ok[i] = 1; ///第i行
    }
}
vector<int> get_row() {
    memset(ok,0,sizeof(ok)) ;
    for(int i = 1;i <= T;i++) {
        test() ;
    }
    vector<int> ans;
    for(int i = 1;i <= n;i++) {
        if(ok[i]) ans.push_back(i) ;
    }
    return ans;
}
vector<int> row , col;
int id(int i,int j) {
    return (i - 1) * col.size() + j ;
}
pair<int,int> to(int k) {
    int c = (k - 1) % col.size() + 1;
    int r = (k - c) / col.size() + 1;
    // printf("RC %d %d\n",r,c);
    return (pair<int,int>){row[r - 1] , col[c - 1]} ;
}
int mat[505][505] , b[505];
int sol[505];
int fpow(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) ans = 1LL * ans * a %mod;
        a = 1LL * a * a %mod; b>>= 1;
    }
    return ans;
}
void solve(int n,int cnt) {
    vector<int> id(n + 1);
    
    for(int i = 1;i < n;i++) {
        int cur = -1;
        for(int j = i;j <= cnt;j++) {
            if(mat[j][i]) {cur = j ;break ;}
        }
        assert(cur != -1) ;
        for(int j = 1;j <= n;j++) swap(mat[i][j] , mat[cur][j]) ;
        swap(b[i] , b[cur]) ;
        int rr = fpow(mat[i][i] , mod - 2) ;
        for(int j = i + 1;j <= cnt;j++) {
            int f = (mod - 1LL * mat[j][i] * rr%mod) % mod;
            for(int k = i;k <= n;k++) mat[j][k] = (mat[j][k] + 1LL * mat[i][k] * f) % mod;
            b[j] = (b[j] + 1LL * b[i] * f) % mod;
        }
    }
    // for(int i = 1;i <= n;i++) {
    //     for(int j = 1;j <= n;j++) printf("%d ",mat[i][j]) ;
    //     printf(": %d\n",b[i]) ;
    // }
    for(int i = n;i >= 1;i--) {
        int sum = b[i];
        for(int j = i + 1;j <= n;j++) {
            sum  = (sum - 1LL * sol[j] * mat[i][j]%mod + mod)  % mod;
        }
        sol[i] = 1LL * sum * fpow(mat[i][i] , mod - 2) % mod;
        // printf("%d %d %d\n",i,sol[id[i]] , id[i]);
    }
    return ;
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    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 >> a2[i][j];
    }
    row = get_row() ;
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j < i;j++) swap(a[i][j] , a[j][i]) , swap(a2[i][j] , a2[j][i]) ;
    }
    col = get_row() ;
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j < i;j++) swap(a[i][j] , a[j][i]) , swap(a2[i][j] , a2[j][i]) ;
    }
    int cnt = 0;
    // printf("R %d %d\n",row.size() , col.size()) ;
    for(int i = 0;i < col.size();i++) {
        for(int j = 1;j <= min(n , 2*(int)row.size());j++) { ///A的第j行,和A'的col[i]列
            int cc = 0; ++cnt ;
            if(j == col[i]) b[cnt] = 1;
            else b[cnt] = 0;
            for(int k = 1;k <= n;k++) {
                if(cc < col.size() && k == row[cc]) { //第k列
                    mat[cnt][id(cc + 1 , i + 1)] = a[j][k] ;
                    ++cc ;
                }
                b[cnt] = (b[cnt] - 1LL * a[j][k] * a2[k][col[i]]%mod + mod) % mod;
            }
        }
    }
    // for(int i = 1;i <= cnt;i++) {
    //     for(int j = 1;j <= cnt;j++) printf("%d ",mat[i][j]) ;
    //     printf(": %d\n",b[i]) ;
    // }
    solve(col.size() * row.size() , cnt) ;
    vector<pair<pii,int> > ans;
    for(int i = 1;i <= cnt;i++) {
        if(sol[i]) {
            // printf("I %d %d\n",i,sol[i]) ;
            pii t = to(i) ;
            ans.push_back({t , (a2[t.first][t.second] + sol[i]) % mod}) ;
        }
    }
    cout << ans.size() << '\n' ;
    sort(ans.begin() , ans.end()) ;
    for(auto [x,y] : ans) {
        cout << x.first <<' ' << x.second <<' ' << y << '\n' ;
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5632kb

input:

1
953176428
107682094

output:

0

result:

ok single line: '0'

Test #2:

score: -100
Wrong Answer
time: 632ms
memory: 36052kb

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:

2
827 238 84815305
827 499 309095694

result:

wrong answer 3rd lines differ - expected: '1466 499 206940592', found: '827 499 309095694'