Submission #778913

#TimeUsernameProblemLanguageResultExecution timeMemory
778913onepunchac168Council (JOI23_council)C++14
100 / 100
819 ms70596 KiB
// created by Dinh Manh Hung // tht.onepunchac168 // THPT CHUYEN HA TINH // HA TINH, VIET NAM #include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3,unroll-loops,no-stack-protector") //#pragma GCC target("sse4,avx2,fma") #define task "" #define ldb long double #define pb push_back #define fi first #define se second #define pc pop_back() #define all(x) begin(x),end(x) #define uniquev(v) v.resize(unique(all(v))-v.begin()) #define FOR(i,a,b) for (int i=a;i<=b;i++) #define cntbit(v) __builtin_popcountll(v) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) ((1LL*a*b)/__gcd(a,b)) #define mask(x) (1LL<<(x)) #define readbit(x,i) ((x>>i)&1) #define ins insert typedef int ll; typedef pair <ll,ll> ii; typedef pair <ll,ii> iii; typedef pair <ii,ii> iiii; ll dx[]= {1,-1,0,0,1,-1,1,-1}; ll dy[]= {0,0,-1,1,1,-1,-1,1}; const ldb PI = acos (-1); //const ll mod=978846151; //const ll base=29; const int maxn=1e6+5; const ll mod=1e9+7; const char nl = '\n'; inline int ReadInt() { char co; for (co = getchar(); co < '0' || co > '9'; co = getchar()); int xo = co - '0'; for (co = getchar(); co >= '0' && co <= '9'; co = getchar()) xo = xo * 10 + co - '0'; return xo; } void WriteInt(int xo) { if (xo > 9) WriteInt(xo / 10); putchar(xo % 10 + '0'); } /* END OF TEMPLATE*/ // ================= Solution =================// const int N=3e5+5; const int M=20+5; ll n,m; ll a[N][M]; ii dp[mask(20)+5][2]; ll dd[25]; void optmushnpr() { cin>>n>>m; for (int i=0; i<mask(m); i++) { for (int j=0; j<=1; j++) { dp[i][j]= {-1e9-5,-1}; } } deque <ii> dq; for (int i=1; i<=n; i++) { ll MASK=0; ll cnt=0; for (int j=0; j<m; j++) { cin>>a[i][j]; if (a[i][j]==0) { MASK+=mask(j); cnt++; } else { dd[j]++; } } if (dp[MASK][0].fi==-1e9-5) { dp[MASK][0]= {cnt,i}; dq.pb({MASK,0}); } else if (dp[MASK][1].fi==-1e9-5) { dp[MASK][1]= {cnt,i}; dq.pb({MASK,1}); } } while (!dq.empty()) { ii aa=dq.front(); dq.pop_front(); ii bb=dp[aa.fi][aa.se]; for (int i=0; i<m; i++) { if (readbit(aa.fi,i)==1) { ll newMASK=aa.fi-mask(i); if (dp[newMASK][0].fi==-1e9-5) { dp[newMASK][0]= {bb.fi-1,bb.se}; dq.pb({newMASK,0}); } else if (dp[newMASK][1].fi==-1e9-5&&bb.se!=dp[newMASK][0].se) { dp[newMASK][1]= {bb.fi-1,bb.se}; dq.pb({newMASK,1}); } } } } for(int MASK = 0; MASK < mask(m); MASK++) { for (int j=0;j<m;j++) { if(readbit(MASK,j)==1) { ll nxt=MASK^mask(j); // first if (dp[MASK][0].fi<dp[nxt][0].fi) { if (dp[MASK][0].se==dp[nxt][0].se) { dp[MASK][0]=dp[nxt][0]; } else { dp[MASK][1]=dp[MASK][0]; dp[MASK][0]=dp[nxt][0]; } } else if (dp[MASK][1].fi<dp[nxt][0].fi&&dp[nxt][0].se!=dp[MASK][0].se) { dp[MASK][1]=dp[nxt][0]; } // second if (dp[MASK][0].fi<dp[nxt][1].fi) { if (dp[MASK][0].se==dp[nxt][1].se) { dp[MASK][0]=dp[nxt][1]; } else { dp[MASK][1]=dp[MASK][0]; dp[MASK][0]=dp[nxt][1]; } } else if (dp[MASK][1].fi<dp[nxt][1].fi&&dp[nxt][1].se!=dp[MASK][0].se) { dp[MASK][1]=dp[nxt][1]; } } } } ll opt=n/2; for (int i=1;i<=n;i++) { ll res=0; ll MASK=0; for (int j=0;j<m;j++) { if (dd[j]>=opt+2) { res++; continue; } if (dd[j]<opt) { continue; } if (dd[j]==opt&&a[i][j]==1) { continue; } if (dd[j]==opt+1&&a[i][j]==0) { res++; continue; } MASK+=mask(j); } if (dp[MASK][0].se!=i) { res+=dp[MASK][0].fi; } else { res+=dp[MASK][1].fi; } cout<<res<<nl; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tests; tests=1; //cin>>tests; while (tests--) { optmushnpr(); } } // goodbye see ya

Compilation message (stderr)

council.cpp: In function 'int main()':
council.cpp:221:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  221 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
council.cpp:222:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  222 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...