제출 #1247500

#제출 시각아이디문제언어결과실행 시간메모리
1247500thdh__Council (JOI23_council)C++20
100 / 100
879 ms78764 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define eb emplace_back #define pu push #define ins insert #define fi first #define se second #define all(a) a.begin(),a.end() #define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fu(x,a,b) for (auto x=a;x<=b;x++) #define fd(x,a,b) for (auto x=a;x>=b;x--) #define int ll using namespace std; //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); /* Competitive Programming notes that I need to study & fix my dumbass self: 1. Coding: - Always be sure to check the memory of arrays (maybe use vectors), for loops - Always try to maximize the memory if possible, even if you are going for subtasks - Do not exploit #define int long long, it will kill you 2. Stress: - Always try generating big testcases and try if they run 3. Time management: - Don't overcommit or undercommit, always spend a certain amount of time to think a problem, don't just look at it and say I'm fucked - Do not spend too much time coding brute-force solutions, they should be easily-codable solutions that don't take up too much time Time management schedule: Offline / LAH days (4 problems - 3h): 15' thinking of solution / idea 1. no idea: skip 2. yes idea: continue thinking for <= 15' + implementing: <= 20' + brute-force: <= 5' + test generator: <= 5' I hate offline because I am dumb */ typedef pair<int, int> ii; const int N = 3e5+5; const int M = 25; const int B = 750; const int mod = 1e9+7; const int inf = 1e18; using cd = complex<double>; const long double PI = acos(-1); int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} int n,m; int a[N][M], cnt[M]; int val[N]; int dp[2000005][2]; int rev(int mask) { return ~mask & ((1<<m) - 1); } int calc(int i, int mask) { return __builtin_popcount(mask & val[i]); } void solve() { cin>>n>>m; for (int i = 0; i < (1<<m); i++) dp[i][0] = dp[i][1] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) { cin>>a[i][j]; if (!a[i][j]) val[i] |= (1<<j); cnt[j] += a[i][j]; } // cout<<val[i]<<" "; if (calc(i, val[i]) > calc(dp[val[i]][0], val[i])) dp[val[i]][1] = dp[val[i]][0], dp[val[i]][0] = i; else if (calc(i, val[i]) > calc(dp[val[i]][1], val[i])) dp[val[i]][1] = i; } for (int i = 0; i < m; i++) { for (int mask = (1<<m)-1; mask >= 0; mask--) { if ((mask>>i & 1) == 0) { int nmask = mask ^ (1<<i); if (dp[nmask][0] != dp[mask][0] && dp[nmask][0] != dp[mask][1]) { int v1 = calc(dp[nmask][0], mask); if (v1 > calc(dp[mask][0], mask)) { dp[mask][1] = dp[mask][0]; dp[mask][0] = dp[nmask][0]; } else if (v1 > calc(dp[mask][1], mask)) { dp[mask][1] = dp[nmask][0]; } } if (dp[nmask][1] != dp[mask][0] && dp[nmask][1] != dp[mask][1]) { int v2 = calc(dp[nmask][1], mask); if (v2 > calc(dp[mask][0], mask)) { dp[mask][1] = dp[mask][0]; dp[mask][0] = dp[nmask][1]; } else if (v2 > calc(dp[mask][1], mask)) dp[mask][1] = dp[nmask][1]; } } } } for (int i = 0; i < m; i++) { for (int mask = 0; mask < (1<<m); mask++) { if (mask>>i & 1) { int nmask = mask ^ (1<<i); if (dp[nmask][0] != dp[mask][0] && dp[nmask][0] != dp[mask][1]) { int v1 = calc(dp[nmask][0], mask); if (v1 > calc(dp[mask][0], mask)) { dp[mask][1] = dp[mask][0]; dp[mask][0] = dp[nmask][0]; } else if (v1 > calc(dp[mask][1], mask)) { dp[mask][1] = dp[nmask][0]; } } if (dp[nmask][1] != dp[mask][0] && dp[nmask][1] != dp[mask][1]) { int v2 = calc(dp[nmask][1], mask); if (v2 > calc(dp[mask][0], mask)) { dp[mask][1] = dp[mask][0]; dp[mask][0] = dp[nmask][1]; } else if (v2 > calc(dp[mask][1], mask)) dp[mask][1] = dp[nmask][1]; } } } } // cout<<dp[3][0].fi<<" "<<dp[3][0].se<<" "<<dp[3][1].fi<<" "<<dp[3][1].se<<endl; // cout<<endl; int bound = n / 2; for (int i = 1; i <= n; i++) { int mask = 0, ans = 0, c = 0; for (int j = 0; j < m; j++) { if (cnt[j] - a[i][j] > bound) ans++; else if (cnt[j] - a[i][j] == bound) { mask |= (1<<j); } } // cout<<endl; // cout<<dp[mask][0].fi<<" "<<dp[mask][0].se<<" "<<dp[mask][1].fi<<" "<<dp[mask][1].se<<" "<<endl; if (dp[mask][0] != i) cout<<ans + __builtin_popcount(mask & val[dp[mask][0]])<<endl; else cout<<ans + __builtin_popcount(mask & val[dp[mask][1]])<<endl; } } /* Go through the mistakes you usually make and revise your code, for god's sake... */ signed main() { bruh //freopen("input.inp","r",stdin); //freopen("output.inp","w",stdout); int t = 1; // cin>>t; while (t--) { solve(); cout<<"\n"; } }
#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...