Submission #813733

#TimeUsernameProblemLanguageResultExecution timeMemory
813733kwongwengRarest Insects (IOI22_insects)C++17
90.14 / 100
82 ms544 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define fi first #define se second #define mi(i) move_inside(i) #define mo(i) move_outside(i) #define pr press_button() int L = 4; int min_cardinality(int n) { vi diff; vi used(n); FOR(i,0,n){ mi(i); int val = pr; if (val >= 2){ mo(i); }else{ diff.pb(i); used[i] = 1; } } int cnt = diff.size(); if (cnt <= L){ for (int u : diff) mo(u); vi num(cnt); FOR(i,0,n){ if (used[i]) continue; mi(i); FOR(j,0,cnt){ mi(diff[j]); if (pr >= 2){ num[j]++; } mo(diff[j]); } mo(i); } int mn = num[0]+1; FOR(i,0,cnt){ mn = min(mn, num[i]+1); } return mn; } vi rem(n); vi taken(n); for (int u : diff) mo(u); int l = 1; int r = n / cnt + 1; int len=0; vi a; while (r-l>1){ int mid = (l+r)/2; FOR(i,0,n){ if (taken[i] || rem[i]) continue; mi(i); len++; if (pr > mid){ mo(i); len--; }else{ a.pb(i); } } if (len == mid * cnt){ l = mid; for (int i : a) taken[i]=1; }else{ r = len/cnt + 1; FOR(i,0,n) rem[i]=1; for (int u : a){ rem[u]=0; taken[u]=0; mo(u); len--; } a.clear(); } } return l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...