Submission #641051

#TimeUsernameProblemLanguageResultExecution timeMemory
641051TimDeeRarest Insects (IOI22_insects)C++17
Compilation error
0 ms0 KiB
#include <cassert> #include <cstdio> #include <algorithm> #include <map> #include <set> #include <string> #include <vector> constexpr int kMaxQueries = 40000; static int N; // Insect types are compressed to colors in the range [0, N). static std::vector<int> color; static std::vector<bool> in_box; static std::vector<int> color_occurrences; static std::multiset<int> max_occurrences; static std::vector<int> op_counter(3, 0); static inline void protocol_violation(std::string message) { printf("Protocol Violation: %s\n", message.c_str()); exit(0); } #include <bits/stdc++.h> void move_inside(int i) { //std::cout<<"inside"<<' '<<i<<'\n'; if (i < 0 || i >= N) { protocol_violation("invalid parameter"); } ++op_counter[0]; if (op_counter[0] > kMaxQueries) { protocol_violation("too many calls"); } if (!in_box[i]) { in_box[i] = true; max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); ++color_occurrences[color[i]]; max_occurrences.insert(color_occurrences[color[i]]); } } void move_outside(int i) { //std::cout<<"outside"<<' '<<i<<'\n'; if (i < 0 || i >= N) { protocol_violation("invalid parameter"); } ++op_counter[1]; if (op_counter[1] > kMaxQueries) { protocol_violation("too many calls"); } if (in_box[i]) { in_box[i] = false; max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); --color_occurrences[color[i]]; max_occurrences.insert(color_occurrences[color[i]]); } } int press_button() { ++op_counter[2]; if (op_counter[2] > kMaxQueries) { protocol_violation("too many calls"); } return *(max_occurrences.rbegin()); } //#include "insects.h" #include <bits/stdc++.h> using namespace std; int n; int min_cardinality(int N) { n=N; int d=0; vector<int> in(n,0); for(int i=0; i<n; ++i) { move_inside(i); int x=press_button(); if (x>1) move_outside(i); else { in[i]=1; ++d; } } if (d==1) return n; if (d==n) return 1; if (d<=0) { for (int i=0; i<n; ++i) { if (in[i]) { in[i]=0; move_outside(i); } } int ans=n; vector<int> vis(n,0); for (int i=0; i<d; ++i) { vector<int> bulaneala; int cnt=0; for (int i=0; i<n; ++i) { if (vis[i]) continue; move_inside(i); int x=press_button(); if (x==cnt) move_outside(i); else { bulaneala.push_back(i); ++cnt; vis[i]=1; } } ans=min(ans,cnt); for (auto x:bulaneala) move_outside(x); } return ans; } int l=1, r=n/d; int now=d; vector<int> laststate=in; while (l<r) { int mid=(l+r+1)>>1; int extra=0; int cnt=now; for (int i=0; i<n; ++i) { if (in[i]) continue; in[i]=1; move_inside(i); int x=press_button(); if (x>mid) { extra=1; move_outside(i); in[i]=0; } else ++cnt; } if (cnt==mid*d) { if (extra==0) { return mid; } else { l=mid; now=cnt; } laststate=in; } else { now=0; r=mid-1; for (int i=0; i<n; ++i) { if ((in[i])&&(laststate[i]==0)) move_outside(i); in[i]=0; } } } return r; } int main() { assert(1 == scanf("%d", &N)); color.resize(N); in_box.assign(N, false); std::map<int, int> type_to_color; for (int i = 0; i < N; ++i) { int Ti; assert(1 == scanf("%d", &Ti)); if (type_to_color.find(Ti) == type_to_color.end()) { int new_color = type_to_color.size(); type_to_color[Ti] = new_color; max_occurrences.insert(0); } color[i] = type_to_color[Ti]; } color_occurrences.assign(type_to_color.size(), 0); int answer = min_cardinality(N); sort(color.begin(), color.end()); //for (auto x:color) cout<<x<<' '; cout<<'\n'; int Q = *std::max_element(op_counter.begin(), op_counter.end()); printf("%d\n", answer); printf("%d\n", Q); return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccjuJkYd.o: in function `move_inside(int)':
stub.cpp:(.text+0x0): multiple definition of `move_inside(int)'; /tmp/cchVzAKb.o:insects.cpp:(.text+0x610): first defined here
/usr/bin/ld: /tmp/ccjuJkYd.o: in function `move_outside(int)':
stub.cpp:(.text+0xe0): multiple definition of `move_outside(int)'; /tmp/cchVzAKb.o:insects.cpp:(.text+0x7e0): first defined here
/usr/bin/ld: /tmp/ccjuJkYd.o: in function `press_button()':
stub.cpp:(.text+0x1c0): multiple definition of `press_button()'; /tmp/cchVzAKb.o:insects.cpp:(.text+0x580): first defined here
/usr/bin/ld: /tmp/ccjuJkYd.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cchVzAKb.o:insects.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status