- Quiz
- AC
- 解説
- 頂点倍化してUnion Find
- 下図を見れば分かるはず
void solve(){ ll N;cin>>N; VI A(N); rep(i, N)cin>>A[i]; SORT(A); ll max_value = A.back(); VI C(max_value+1); // count for(ll a : A)C[a]++; VI B = A; // unique values auto it = unique(ALL(B)); B.erase(it, B.end()); VI exist(max_value+1); for(ll b : B)exist[b]=1; auto dp = C; ll max_group_size=MAX(dp); for(ll b : B){ FOR(i,2,max_value+1){ ll v = i*b; if(v>max_value)break; if(exist[v]){ chmax(dp[v], dp[b]+C[v]); chmax(max_group_size, dp[v]); } } } ll ans = N-max_group_size; p(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N;cin>>N; while(N--)solve(); return 0; }
F:bを零行列にしてもよい。1文字目が1であるような行に操作を行って、各行がすべて等しくなるかどうか
— いのはらこぼし (競プロ) (@koboshi_kyopro) January 26, 2021
G:ゆきこで見た気がする。xを末尾とする最長増加列の長さを計算
こどふぉ #697 div3
— keroru (@keroru10) January 25, 2021
A 2でひたすら割る
B 2021*2020以上は大丈夫、以下は2020の数で全探索
C 各人から出る辺の数をカウント
D 尺取りでバグったので累積和を二分探索
E k番目の数をmとするとC(mの個数,k-mより大きい数の個数)
F AxorBを0にできるかどうかは、全行が一行目と同じか、その反転のどちらか
たしかにそうっぽいが天才感がある。もっと再現性のある方法はないか?ということで以下に続く
// for codeforces void solve(){ ll N; cin>>N; VV A(N, VI(N)); VV B(N, VI(N)); rep(i,N){ string s;cin>>s; rep(j,N){ if(s[j]=='1')A[i][j]=1; } } rep(i,N){ string s;cin>>s; rep(j,N){ if(s[j]=='1')B[i][j]=1; } } rep(i,N){ rep(j,N){ A[i][j] ^= B[i][j]; } } auto A_original = A; // 1週目 1行目をswapしない場合 // 2週目 1行目をswapした場合 rep(_,2){ A = A_original; if(_==0){ // 1行目をswap rep(i,N){ A[0][i] ^= 1; } } // check // 1行目を見て、列のswapが必要な箇所は今1である部分 rep(x,N){ if(A[0][x]==1){ // その列は全てswapする rep(y,N){ A[y][x] ^= 1; } } } bool ok=true; FOR(y,1,N){ // 残りの行は0にできるか // 全部0か、全部1なら横swapにより可能 ll sum = SUM(A[y]); if(sum==0 or sum==N){ // safe }else{ ok=false; } } if(ok){ p_yes();return; } } p_no(); } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N;cin>>N; while(N--)solve(); return 0; }
void solve(){ ll N; cin>>N; // width => (height, index) map<ll, vector<PII>> mp; rep(i,N){ ll w,h;cin>>w>>h; // assume w >= h if(h>w)swap(w,h); mp[w].push_back({h,i}); } VI Ans(N,-2); ll min_height=inf; ll min_height_index=-1; for(auto pa : mp){ ll w = pa.first; ll local_min_height=inf; ll local_min_height_idx=-1; for(auto h_i : pa.second){ ll h = h_i.first; ll idx = h_i.second; if(min_height<h){ // found! Ans[idx]=min_height_index; } if(chmin(local_min_height,h)){ local_min_height_idx = idx; } } // finally, update for next width if(chmin(min_height, local_min_height)){ min_height_index = local_min_height_idx; } } print_vector(Ans,1); } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N; cin>>N; while(N--)solve(); return 0; }