Submission #1086876

#TimeUsernameProblemLanguageResultExecution timeMemory
1086876coldbr3wCouncil (JOI23_council)C++17
100 / 100
567 ms54148 KiB
#include <bits/stdc++.h> using namespace std; #define ll int #define pll pair<int, int> #define pb push_back #define F first #define S second #define all(x) (x).begin(), (x).end() const ll N = 2e6 + 100; const ll inf = 1e9; const ll mod = 1e9 + 7; const ll block = 350; ll n,m; ll a[N][21], res[N], cnt[N]; void to_thic_cau(){ cin >> n >> m; vector<pair<pair<int, int>, pair<int, int>>> dp(1 << m, {{-1, -1}, {-1, -1}}); auto upd = [&](int msk, pair<int, int> val) -> void { if (val.second == dp[msk].first.second or val.second == dp[msk].second.second) return; if (dp[msk].first.first < val.first) dp[msk].first = val; else if (dp[msk].second.first < val.first) dp[msk].second = val; }; for(int i = 1; i <= n;i++){ ll msk = 0; for(int j = 0; j < m;j++){ cin >> a[i][j]; if(a[i][j] == 1) cnt[j]++; else cnt[j]--, msk |= (1 << j); } upd(msk, {__builtin_popcount(msk), i}); } for (int msk = (1 << m) - 1; msk >= 0; --msk) { for (int i = 0; i < m; ++i) if (msk >> i & 1) { upd(msk ^ (1 << i), {dp[msk].first.first - 1, dp[msk].first.second}); upd(msk ^ (1 << i), {dp[msk].second.first - 1, dp[msk].second.second}); } } for (int i = 0; i < m; ++i) for (int msk = 0; msk < 1 << m; ++msk) if (msk >> i & 1) { int nxt_msk = msk ^ (1 << i); upd(msk, dp[nxt_msk].first); upd(msk, dp[nxt_msk].second); } for (int i = 1; i <= n; ++i) { for (int j = 0; j < m; ++j) { cnt[j] -= (a[i][j] ? 1 : -1); } int needed_msk = 0; for (int j = 0; j < m; ++j) { if (cnt[j] == 0 or cnt[j] == 1) needed_msk |= (1 << j); } int needed_idx = (dp[needed_msk].first.second != i ? dp[needed_msk].first.second : dp[needed_msk].second.second); for (int j = 0; j < m; ++j) { cnt[j] -= (a[needed_idx][j] ? 1 : -1); } int res = 0; for (int j = 0; j < m; ++j) if (cnt[j] > 0) ++res; cout << res << "\n"; for (int j = 0; j < m; ++j) { cnt[j] += (a[needed_idx][j] ? 1 : -1); cnt[j] += (a[i][j] ? 1 : -1); } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); ll tc = 1; //cin >> tc; while(tc--) to_thic_cau(); }
#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...