[NOI2013]向量內積

/*
以如今的機器速度, 不使用bitset的暴力是能跑到75分的
考慮在取模意義下的特殊狀況, 維護a數組的每一維的前綴和,總體來作, 那麼在一次統計中得不到一個答案的機率是$\frac{1}{2}$
至於取mod爲三的狀況 咱們發現雖然mod不爲0的狀況多是1 或者2 可是他們兩個在mod3 意義下平方後都是1
按照這個性質維護便可
 
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll long long
#define M 100010
#define mmp make_pair
using namespace std;
int read() {
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}
int a[M][105], n, d, k, rd[M], tmp[105][105], tmd[105];


int work(int now) {
    int ans = 0;
    if(k == 2) {
        for(int i = 1; i <= d; i++) {
            ans ^= a[now][i] * tmd[i];
            tmd[i] ^= a[now][i];
        }
    } else {
        for(int i = 1; i <= d; i++)
            for(int j = 1; j <= d; j++) {
                ans += a[now][i] * a[now][j] * tmp[i][j];
                tmp[i][j] += a[now][i] * a[now][j];
            }
    }
    return ans % k;
}


bool check(int i, int j) {
    int ans = 0;
    for(int z = 1; z <= d; z++) ans += a[i][z] * a[j][z];
    ans %= k;
    return ans == 0;
}

int main() {
    srand(20020216);
    n = read(), d = read(), k = read();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= d; j++)
            a[i][j] = read() % k;
    }
    for(int i = 1; i <= n; i++) rd[i] = i;
    for(int T = 1; T; T--) {
        random_shuffle(rd + 1, rd + n + 1);
        for(int i = 1; i <= n; i++) {
            if(work(rd[i]) == ((i - 1) % k)) continue;
            //  cout << "!";
            for(int j = 1; j < i; j++) if(check(rd[i], rd[j])) {
                    if(rd[i] > rd[j]) swap(rd[i], rd[j]);
                    cout << rd[i] << " " << rd[j] << "\n";
                    return 0;
                }
        }
        memset(tmp, 0, sizeof(tmp));
        memset(tmd, 0, sizeof(tmd));
    }
    puts("-1 -1");
    return 0;
}
/*
5 2 3
1 1
1 1
1 1
1 1
1 1

*/
相關文章
相關標籤/搜索