Submission #1080000

# Submission time Handle Problem Language Result Execution time Memory
1080000 2024-08-29T05:56:19 Z LittleOrange Rarest Insects (IOI22_insects) C++17
25 / 100
256 ms 596 KB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
  vector<ll> p;
  dsu(ll n):p(n,-1){}
  ll g(ll i){
    return p[i]<0?i:p[i] = g(p[i]);
  }
  bool m(ll a, ll b){
    a = g(a),b = g(b);
    if (a==b) return false;
    if(p[a]>p[b]) swap(a,b);
    p[a] += p[b];
    p[b] = a;
    return true;
  }
};
int min_cardinality(int n) {
  mt19937_64 mt(random_device{}());
  vector<ll> a(n);
  iota(a.begin(),a.end(),0);
  dsu d(n);
  ll run = 1;
  while(run){
    run = 0;
    shuffle(a.begin(),a.end(),mt);
    vector<ll> v;
    for(ll i : a) if(d.p[i]<0) v.push_back(i);
    ll l = 0;
    for(ll i = 0;i<v.size();i++){
      move_inside(v[i]);
      if (i>0&&press_button()>1){
        do{
          move_outside(v[l++]);
        }while(press_button()>1);
        d.m(v[l-1],v[i]);
        run = 1;
      }
    }
    while(l<v.size())move_outside(v[l++]);
  }
  ll ans = -n;
  for(ll i : d.p) if(i<0)ans = max(ans,i);
  return -ans;
}
 

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:32:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(ll i = 0;i<v.size();i++){
      |                  ~^~~~~~~~~
insects.cpp:42:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     while(l<v.size())move_outside(v[l++]);
      |           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 424 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 9 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 9 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 12 ms 344 KB Output is correct
21 Correct 11 ms 340 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 424 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 9 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 9 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 12 ms 344 KB Output is correct
21 Correct 11 ms 340 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 10 ms 344 KB Output is correct
24 Correct 5 ms 340 KB Output is correct
25 Correct 48 ms 344 KB Output is correct
26 Correct 39 ms 344 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 18 ms 344 KB Output is correct
29 Correct 19 ms 344 KB Output is correct
30 Correct 46 ms 344 KB Output is correct
31 Correct 17 ms 344 KB Output is correct
32 Correct 17 ms 344 KB Output is correct
33 Correct 24 ms 344 KB Output is correct
34 Correct 41 ms 344 KB Output is correct
35 Correct 37 ms 344 KB Output is correct
36 Correct 48 ms 344 KB Output is correct
37 Correct 69 ms 344 KB Output is correct
38 Correct 98 ms 344 KB Output is correct
39 Correct 141 ms 344 KB Output is correct
40 Correct 162 ms 344 KB Output is correct
41 Correct 176 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 13 ms 592 KB Output is correct
9 Partially correct 167 ms 452 KB Output is partially correct
10 Partially correct 160 ms 592 KB Output is partially correct
11 Correct 26 ms 344 KB Output is correct
12 Correct 27 ms 440 KB Output is correct
13 Partially correct 39 ms 344 KB Output is partially correct
14 Partially correct 118 ms 440 KB Output is partially correct
15 Partially correct 46 ms 344 KB Output is partially correct
16 Partially correct 56 ms 596 KB Output is partially correct
17 Partially correct 53 ms 444 KB Output is partially correct
18 Partially correct 61 ms 444 KB Output is partially correct
19 Partially correct 79 ms 592 KB Output is partially correct
20 Partially correct 97 ms 344 KB Output is partially correct
21 Partially correct 148 ms 344 KB Output is partially correct
22 Partially correct 197 ms 592 KB Output is partially correct
23 Incorrect 256 ms 592 KB Too many queries.
24 Halted 0 ms 0 KB -