# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729102 | shadow_sami | Council (JOI23_council) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pi;
typedef map<ll,ll> mi;
typedef long double ld;
typedef vector<ld> vd;
typedef vector<vector<ld>> vvd;
typedef pair<ld,ld> pd;
#define ff first
#define ss second
#define srt(a) sort(a.begin(),a.end());
#define fip(k, n) for (ll i = k; i < n; i++)
#define fjp(k, n) for (ll j = k; j < n; j++)
#define fin(k, n) for (ll i = k; i >= n; i--)
#define fjn(k, n) for (ll j = k; j >= n; j--)
#define fp(k, n, m) for (ll k = n; k < m; k++)
#define fn(k, n, m) for (ll k = n; k >= m; k--)
#define ordered_set tree<pi, null_type,less< pi >, rb_tree_tag,tree_order_statistics_node_update>
#define totalOne(n) __builtin_popcount(n)
#define backZero(n) __builtin_ctzll(n)
#define frontZero(n) __builtin_clzll(n)
#define fx(k) for ( auto x : k )
#define test ll t;cin >> t;while (t--)
#define nli "\n"
ll n,m,tp,tp2,res,cnt,ans,sum,tptp;
const ll mx = 300000+5;
const ll mod = 1e9+7;;
//void prime_sieve();
// ll gcd(ll a,ll b);
ll mod_power(ll aa,ll bb);
ll mod_add(ll aa,ll bb){
aa%=mod;
bb%=mod;
return (aa+bb)%mod;
}
ll mod_minus(ll aa,ll bb){
aa%=mod;
bb%=mod;
return ((aa-bb)+mod)%mod;
}
ll mod_mul(ll aa,ll bb){
aa%=mod;
bb%=mod;
return (aa*bb)%mod;
}
ll mod_divi(ll aa,ll bb){
aa=mod_mul(aa,mod_power(bb,mod-2));
return aa;
}
ll mod_power(ll aa,ll bb){
aa%=mod;
ll empowered = 1;
bb%=mod-1;
while(bb > 0){
if(bb & 1)
empowered = mod_mul(empowered,aa);
bb = bb >> 1;
aa = mod_mul(aa,aa);
}
return empowered;
}
bool f = false;
ll val[mx][20];
pi dp[20][2];
pi dp2[20][2];
ll tnc[20][2];
ll vote[20],score;
unordered_map<ll,pi> mp;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
cin>>n>>m;
fip(0,20)
fjp(0,2)
dp[i][j] = {-1,-1},tnc[i][j]=0,dp2[i][j]={-1,-1};
fip(0,n){
fjp(0,m)
cin>>val[i][j];
tp = 0;
fjp(0,m)
if(val[i][j])
tp |= (1<<j);
mp[tp].ff++;
mp[tp].ss = i;
}
fip(0,n)
fjp(0,m)
if(val[i][j])
vote[j]++;
score = 0;
fjp(0,m)
if(vote[j]>=(n/2))
score++;
fjp(0,m)
cout<<j<<" "<<vote[j]<<nli;
cout<<score<<nli;
fip(0,n){
fjp(0,m)
if(val[i][j])
vote[j]--;
tp = 0;
fjp(0,20)
if(vote[j]>=(n/2))
tp++;
fjp(0,m){
tnc[j][val[i][j]]++;
if(dp[j][val[i][j]].ff == -1)
dp[j][val[i][j]] = {i,tp};
else{
if(dp[j][val[i][j]].ss<tp){
dp2[j][val[i][j]] = {dp[j][val[i][j]].ff,dp[j][val[i][j]].ss};
dp[j][val[i][j]] = {i,tp};
}else if(dp2[j][val[i][j]].ff==-1)
dp2[j][val[i][j]] = {i,tp};
else if(dp2[j][val[i][j]].ss < tp)
dp2[j][val[i][j]] = {i,tp};
}
}
fjp(0,m)
if(val[i][j])
vote[j]++;
}
// fip(0,20)
// fjp(0,2){
// cout<<i<<" pos "<<j<<nli;
// if(tnc[i][j])
// cout<<dp[i][j].ff<<" "<<dp[i][j].ss<<" "<<dp2[i][j].ff<<nli;
// }
fip(0,n){
fjp(0,m)
if(val[i][j])
vote[j]--;
ll na = -INT_MAX;
ll temp;
pi pos;
fjp(0,20)
fp(x,0,2){
if(tnc[j][x]==1)
if(dp[j][x].ff==i)
continue;
if(tnc[j][x]){
tp = dp[j][x].ff;
if(tp==i)
tp = dp2[j][x].ff;de
fp(y,0,m)
if(val[tp][y])
vote[y]--;
temp = 0;
fp(y,0,m)
if(vote[y]>=(n/2))
temp++;
if(temp>na){
na = temp;
pos = {j,x};
}
fp(y,0,m)
if(val[tp][y])
vote[y]++;
}
}
fjp(0,m)
if(val[i][j])
vote[j]++;
cout<<na<<nli;
}
// fip(0,n)
// fjp(0,m)
// cout<<val[i][j]<<nli;
// cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
// void prime_sieve(){
// for(ll i = 2; i*i<=mx;i++)
// if(dp[i])
// for(ll j = i*i; j<mx; j+=i)
// dp[j] = false;
// dp[1] = dp[0] = false;
// return;
// }