結果

問題 No.2505 matriX cOnstRuction
ユーザー 👑 potato167potato167
提出日時 2023-10-17 03:16:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,183 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 223,076 KB
実行使用メモリ 63,696 KB
最終ジャッジ日時 2023-10-17 03:16:34
合計ジャッジ時間 12,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 17 ms
4,348 KB
testcase_02 AC 15 ms
4,348 KB
testcase_03 AC 15 ms
4,348 KB
testcase_04 AC 15 ms
4,348 KB
testcase_05 AC 15 ms
4,348 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 11 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 11 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 11 ms
4,348 KB
testcase_18 AC 11 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 10 ms
4,348 KB
testcase_24 AC 11 ms
4,348 KB
testcase_25 AC 11 ms
4,348 KB
testcase_26 AC 10 ms
4,348 KB
testcase_27 AC 10 ms
4,348 KB
testcase_28 AC 11 ms
4,348 KB
testcase_29 AC 11 ms
4,348 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 148 ms
18,288 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p,int ty=0){
if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}



void solve();
// oddloop
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t=1;
    cin>>t;
    rep(i,0,t) solve();
}

void solve(){
    int N,M;
    cin>>N>>M;
    vector<int> p(N),q(M);
    rep(i,0,N) cin>>p[i];
    rep(i,0,M) cin>>q[i];
    vector<vector<int>> A(N,vector<int>(M));
    rep(i,0,N) rep(j,0,M) cin>>A[i][j];
    vector<int> X(N),Y(M);
    Y=A[0];
    rep(i,0,N) X[i]=(A[i][0]^Y[0]);
    rep(i,0,N) rep(j,0,M){
        if(A[i][j]^X[i]^Y[j]){
            cout<<"-1\n";
            return;
        }
    }
    rep(i,0,M) p.push_back(q[i]),X.push_back(Y[i]);
    map<int,int> m;
    map<int,int> dp;
    rep(i,0,N+M){
        int tmp1=p[i],tmp2=X[i],tmp3=1;
        tmp1++;
        while(tmp3<tmp1) tmp3*=2;
        for(int d=29;d>=0;d--){
            if(tmp1&(1<<d)){
                int l=(((1<<30)-(1<<d))&(tmp1^tmp2^(1<<d)));
                int r=l+(1<<d);
                dp[l]--,dp[r]++;
            }
            if(tmp3&(1<<d)){
                int l=(((1<<30)-(1<<d))&(tmp3^tmp2^(1<<d)));
                int r=l+(1<<d);
                dp[l]+=2,dp[r]-=2;
                m[l]++,m[r]--;
            }
        }
        dp[X[i]]--,dp[X[i]+1]++;
    }
    int ans=INF;
    int tmp=0;
    int v=0;
    for(auto x:dp){
        tmp+=m[x.first];
        v+=x.second;
        //cout<<x.first<<" "<<tmp<<" "<<v<<endl;
        if(tmp==N+M) chmin(ans,v);
    }
    if(ans!=INF) cout<<ans<<"\n";
    else cout<<"-1\n";
}
0