Submission #727527

#TimeUsernameProblemLanguageResultExecution timeMemory
727527YassineBenYounesRarest Insects (IOI22_insects)C++17
57.42 / 100
161 ms600 KiB
#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 = 13;

vi arr[mx];
int sol[mx];
int color[mx], res[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(auto x : mp){
            cout << x.ff << " " << x.ss << endl;
        }
        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;
    }
    
    int st = 1;
    int a = 0;
    int stop = 0;
    while(st <= stop){
        int x = 0;
        for(int i = 0; i < n;i++){
            if(vis[i])continue;
            move_inside(i);
            int v = press_button();
            if(v == st+2){
                move_outside(i);
            }
            else{
                vis[i] = 1;
                x++;
            }
        }
        if(x != c-1){
            return st;
        }
        st++;
    }
    for(auto x : mp){
        cout << x.ff << " " << x.ss << endl;
    }
    
    int l = 1, r = n/(c-1);
    int ans = 0;
    while(l <= r){
        int md = (l+r)/2;
        int x = (stop+1) * (c-1);
        vi ve;
        int last = 0;
        for(int i = 0; i < n;i++){
            if(color[i] != 0)continue;
            move_inside(i);
            int v = press_button();
            if(v <= md){
                x++;
                ve.pb(i);
            }
            else{
                move_outside(i);
            }
            last = v;
        }
        //cout << endl;
        for(int x : ve)move_outside(x);
        int sup = md * (c-1);
        if(x < sup){
            r = md-1;
        }
        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 'int min_cardinality(int)':
insects.cpp:158:13: warning: variable 'last' set but not used [-Wunused-but-set-variable]
  158 |         int last = 0;
      |             ^~~~
insects.cpp:127:9: warning: unused variable 'a' [-Wunused-variable]
  127 |     int a = 0;
      |         ^
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...