# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
796066 | vjudge1 | Council (JOI23_council) | C++17 | 2279 ms | 90476 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Author : حسن
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 3e5 + 9 , mod = 1e9 + 7;
ll c[N] = {} , d[N] = {} , a[N][22] = {}, b[N] = {} , us[N] , dp[N * 4][4] = {};
void solve(){
ll q , i , j , m , n , z , s = 0, f, l , r , k , x , y , mn = 1e18 , mx = 0;
cin>>n>>m;
for(i = 0; i <= (1 << 20); i++)
dp[i][0] = dp[i][1] = dp[i][2] = dp[i][3] = 0 , dp[i][1] = -1;
for(i = 1;i <= n; i++)
for(j = 0; j < m; j++){
cin>>a[i][j] , b[j] += a[i][j];
if(a[i][j])
d[i] += a[i][j] , c[i] += (1 << j);
}
y = n / 2;
for(i = 1; i <= n; i++){
x = c[i] , c[i] = ((1 << m) - 1) ^ c[i];
if(dp[c[i]][1] == -1)
dp[c[i]][1] = i , dp[c[i]][0] = m - d[i];
else
dp[c[i]][3] = i , dp[c[i]][2] = m - d[i];
c[i] = x;
}
for(i = (1 << m) - 1; i >= 0; i--){
for(j = 0; j < m; j++){
if(i & (1 << j)){
x = i ^ (1 << j);
dp[i][0]--;
dp[i][2]--;
vector<pair<ll,ll>>v;
v.pb({dp[i][0] , dp[i][1]});
v.pb({dp[i][2] , dp[i][3]});
v.pb({dp[x][0] , dp[x][1]});
v.pb({dp[x][2] , dp[x][3]});
sort(rall(v));
dp[x][0] = v[0].fi , dp[x][1] = v[0].se;
for(auto to : v)
if(to.se != dp[x][1]){
dp[x][2] = to.fi , dp[x][3] = to.se;
break;
}
dp[i][0]++;
dp[i][2]++;
}
}
}
for(i = 0; i < (1<<m); i++){
for(j = 0; j < m; j++){
if(!((1 << j) & i)){
x = i ^ (1 << j);
vector<pair<ll,ll>>v;
v.pb({dp[i][0] , dp[i][1]});
v.pb({dp[i][2] , dp[i][3]});
v.pb({dp[x][0] , dp[x][1]});
v.pb({dp[x][2] , dp[x][3]});
sort(rall(v));
dp[x][0] = v[0].fi , dp[x][1] = v[0].se;
for(auto to : v)
if(to.se != dp[x][1]){
dp[x][2] = to.fi , dp[x][3] = to.se;
break;
}
}
}
}
for(j = 0; j < m; j++)
s += (b[j] >= y);
for(i = 1; i <= n; i++){
mx = 0;
for(j = 0; j < m; j++){
b[j] -= a[i][j];
if(a[i][j] == 1 && b[j] == y - 1)
s--;
}
f =x = 0;
for(j = 0; j < m; j++){
if(b[j] == y) x += (1 << j);
else if(b[j] > y) f++;
}
k = dp[x][0];
if(dp[x][1] == i)
k = dp[x][2];
//cout<<s<<" ";
cout<<f + k<<"\n";
for(j = 0; j < m; j++){
b[j] += a[i][j];
if(a[i][j] == 1 && b[j] == y)
s++;
}
}
}
int main(){
TL;
/*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
int t = 1;
//cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |