Submission #727518

#TimeUsernameProblemLanguageResultExecution timeMemory
727518YassineBenYounesRarest Insects (IOI22_insects)C++17
47.50 / 100
237 ms660 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 = sqrt(mx); vi arr[mx]; int sol[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); } } for(int i = 0; i < n;i++){ if(color[i] != 0){ move_outside(i); } } int l = 1, r = n; int ans = 0; while(l <= r){ int md = (l+r)/2; int x = 0; vi ve; for(int i = 0; i < n;i++){ move_inside(i); int v = press_button(); if(v <= md){ x++; ve.pb(i); } else{ move_outside(i); } } 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 '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...