Submission #1232479

#TimeUsernameProblemLanguageResultExecution timeMemory
1232479nibertNile (IOI24_nile)C++20
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <fstream> #include <algorithm> #include "nile.h" using namespace std; struct dsu { vector<int> parent, rank; dsu (int n) { parent.resize(n,-1); rank.resize(n,1); } int find(int x) { return(parent[x]== -1) ? x: (parent[x] = find(parent[x])); } void merge(int u, int v){ int rootU = find(u); int rootV = find(v); if(rootU != rootV) { if(rank[rootU] > rank[rootV]) { parent[rootV] = rootU; } else if (rank[rootU] < rank[rootV]) { parent[rootU] = rootV; } else { parent[rootV] = rootU; rank[rootU]++; } } } }; int find_best_pair(const vector<int> &w, int left, int d) { int low = left + 1, high = w.size()-1; int best = -1; while (low <= high){ int mid = (low+high) /2; if(w[mid]-w[left] <=d){ if(best == -1 || w[mid] - w[left] < w[best] - w[left]) { best = mid; } high = mid -1; } else{ high = mid - 1; } } return best; } int boat_count(vector<int> w, int d) { int N = w.size(); sort(w.begin(), w.end()); dsu boats(N); vector <bool> paired(N,false); for (int i = 0; i < N; i ++) { if(paired[i]) { continue; } int best_pair = find_best_pair(w,i,d); if(best_pair != -1) { boats.merge(i,best_pair); paired[best_pair] = true; } } int boat_count = 0; for(int i = 0; i < N; i++) { if(boats.find(i) == i){ boat_count++; } } return boat_count; } int main() { ifstream file("n2.txt",ios::in); int n; file >> n; vector<int> w(n); for(int i = 0; i <n; i ++) { file >> w[i]; } int d; file >> d; cout << "Number of boats if only two weights go on a boat is " << boat_count(w,d); return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/cceSX3Xt.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccYw5Tzo.o:nile.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cceSX3Xt.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `calculate_costs(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status