This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vdd vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////
void usaco_problem(){
freopen("milkvisits.in", "r", stdin);
freopen("milkvisits.out", "w", stdout);
}
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = 2005;
const int LOG = 25;
const int inf = 1e9;
const ll mod = 1e8;
map<int, int> mp;
ll bs = 0;
vi arr[mx];
int color[mx];
bool vis[mx];
void move_inside(int i);
void move_outside(int i);
int press_button();
int min_cardinality(int n){
int c = 1;
for(int i = 0; i < n;i++){
move_inside(i);
int v = press_button();
if(v==1){
color[i] = c;
arr[c].pb(i);
c++;
}
if(v == 2){
move_outside(i);
}
}
if(c <= bs){
for(int i = 0; i < n;i++){
if(color[i] != 0){
move_outside(i);
}
}
for(int i = 1; i < c;i++){
for(int x : arr[i]){
move_inside(x);
vis[x] = 1;
}
for(auto x : mp){
cout << x.ff << " " << x.ss << endl;
}
cout << endl;
int st = 2;
for(int j = 0;j < n;j++){
if(vis[j])continue;
move_inside(j);
int v = press_button();
if(v == st){
color[j] = i;
vis[j] = 1;
st++;
arr[i].pb(j);
}
else{
move_outside(j);
}
}
for(int x : arr[i]){
move_outside(x);
}
}
int ans = 1e9;
for(int i = 1; i < c;i++){
int s = arr[i].size();
ans = min(ans, s);
}
return ans;
}
for(int i = 0; i < n;i++){
if(color[i] != 0){
vis[i] = 1;
}
}
int l = 1, r = n/(c-1);
int ans = 0;
vi ve;
vi no(n+5);
while(l <= r){
int md = (l+r)/2;
int x = (c-1) + ve.size();
vi nw;
vi temp(n+5);
int sup = md * (c-1);
for(int i = 0; i < n && x < sup;i++){
if(vis[i] || no[i])continue;
move_inside(i);
int v = press_button();
if(v <= md){
x++;
ve.pb(i);
nw.pb(i);
vis[i]= 1;
}
else{
temp[i] = 1;
move_outside(i);
}
}
if(x < sup){
r = md-1;
for(int x : nw){
ve.erase(find(all(ve), x));
move_outside(x);
vis[x] = 0;
}
for(int i = 0; i < n;i++){
no[i] |= temp[i];
}
}
else{
ans = md;
l = md+1;
}
}
return ans;
}
/*
void run_case(){
int n;cin >> n;
for(int i = 0; i < n;i++){
cin >> sol[i];
}
cout << min_cardinality(n) << endl;
}
int main(){
init();
speed;
int t;
//cin >> t;
t = 1;
while(t--){
run_case();
}
}*/
/*
NEVER GIVE UP!
DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
Your Guide when stuck:
- Continue keyword only after reading the whole input
- Don't use memset with testcases
- Check for corner cases(n=1, n=0)
- Check where you declare n(Be careful of declaring it globally and in main)
*/
Compilation message (stderr)
insects.cpp: In function 'void usaco_problem()':
insects.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen("milkvisits.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insects.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen("milkvisits.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insects.cpp: In function 'void init()':
insects.cpp:40:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
insects.cpp:42:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |