Submission #1125992

#TimeUsernameProblemLanguageResultExecution timeMemory
1125992finalventureRobots (IOI13_robots)C++20
Compilation error
0 ms0 KiB
// #include "robots.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define all(x) (x).begin(), (x).end() #define pb(x) push_back(x) #define EPS 1e-9 void init() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); } // Approach: greedily use the worst robot possible that will make future robots' lives easier // i.e. use weakest robot and pick up biggest items, and so on // appear[i] contains all toys that can be picked up by weak robot i vector<vector<int>> appear; vector<int> sizes; bool check(int time) { int n = appear.size(); priority_queue<int> pq; for (int i = 0; i < n - 1; ++i) { int nn = appear[i].size(); for (int j = 0; j < nn; ++j) { pq.push(appear[i][j]); } int pqsz = pq.size(); // We no longer have to consider using this robot again because it's too weak for further toys for (int j = 0; j < min(time, pqsz); ++j) { pq.pop(); } } for (int j = 0; j < appear[n - 1].size(); ++j) { pq.push(appear[n - 1][j]); } for (int i = 0; i < sizes.size(); ++i) { int pqsz = pq.size(); for (int j = 0; j < min(pqsz, time); ++j) { int tsz = pq.top(); if (tsz >= sizes[i]) break; pq.pop(); } } if (pq.empty()) return true; return false; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { sizes.resize(B); for (int i = 0; i < B; ++i) { sizes[i] = Y[i]; } appear.resize(A + 1); sort(X, X + A); // weight limit of robots sort(sizes.begin(), sizes.end()); // size limit of robots for (int i = 0; i < T; ++i) { int idx = upper_bound(X, X + A, W[i]) - X; int idx2 = upper_bound(sizes.begin(), sizes.end(), S[i]) - sizes.begin(); if (idx == A && idx2 == B) return -1; appear[idx].push_back(S[i]); } reverse(sizes.begin(), sizes.end()); for (int i = 0; i < A + 1; ++i) { sort(appear[i].begin(), appear[i].end(), greater<int>()); } int l = 1, r = T + 10; while (l < r) { // cout << l << ' ' << r << endl; int m = l + (r - l) / 2; if (check(m)) { r = m; } else { l = m + 1; } } return l; } signed main() { init(); int A, B, T; cin >> A >> B >> T; int X[A], Y[B], W[T], S[T]; for (int i = 0; i < A; ++i) { cin >> X[i]; } for (int i = 0; i < B; ++i) { cin >> Y[i]; } for (int i = 0; i < T; ++i) { cin >> W[i] >> S[i]; } cout << putaway(A, B, T, X, Y, W, S) << endl; return 0; }

Compilation message (stderr)

robots.cpp: In function 'void init()':
robots.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
robots.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccSJr0Sa.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5S02C5.o:robots.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccSJr0Sa.o: in function `main':
grader.c:(.text.startup+0x1a1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status