Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- #define ppb pop_back
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- _test
- {
- ll int n, m;
- cin>>n>>m;
- vector<vector<int>> a(n, vector<int> (m));
- for(auto &b: a) for(auto &e: b) cin>>e;
- ll int tot = 0;
- vector<vector<int>> row(n, vector<int> (30));
- vector<vector<int>> col(m, vector<int> (30));
- vector<int> cnt(30);
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- for(int b=0; b<30; b++)
- {
- if(((1<<b)&a[i][j]) > 0)
- {
- cnt[b]++;
- row[i][b]++;
- col[j][b]++;
- }
- }
- }
- }
- ll int ans = 0;
- vector<int> tmp(30);
- ll int val = 0;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- val = 0;
- for(int b=0; b<30; b++)
- tmp[b] = cnt[b] - row[i][b] - col[j][b] + (((1<<b)&a[i][j])>0);
- for(int b=0; b<30; b++)
- {
- if(((1<<b)&a[i][j]) == 0)
- val += tmp[b]*1ll*(1<<b);
- else
- val += ((n*1ll*m -n-m +1ll) - tmp[b])*1ll*(1<<b);
- }
- ans = max(ans, val);
- }
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment