Submission #241648

#TimeUsernameProblemLanguageResultExecution timeMemory
241648abacabaRobots (IOI13_robots)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include "robots.h" #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define emb emplace_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } inline void setin(string s) { freopen(s.c_str(), "r", stdin); } inline void setout(string s) { freopen(s.c_str(), "w", stdout); } template <typename T> void Min(T &a, T b) { a = min(a, b); } template <typename T> void Max(T &a, T b) { a = max(a, b); } const int inf = 2e9; const int mod = 998244353; const int N = 1e6 + 15; int a[N], b[N]; pii s[N]; int n, m, t; bool used[N]; int cnt[2][N]; set <pii> is; inline bool check(int mid) { is.clear(); for(int i = 1; i <= n; ++i) { cnt[0][i] = mid; is.insert({a[i], i}); } for(int i = 1; i <= m; ++i) cnt[1][i] = mid; for(int i = 1; i <= t; ++i) { used[i] = false; set <pii>::iterator it = is.upper_bound({s[i].se, inf}); if(it == is.end()) continue; used[i] = true; if(--cnt[0][it->se] == 0) is.erase(it); } for(int i = 1, j = 1; i <= t; ++i) { if(!used[i]) { if(cnt[1][j] == 0) ++j; if(j > m || b[j] <= s[i].f) return false; cnt[1][j]--; used[i] = true; } } return true; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { n = A, m = B, t = T; for(int i = 0; i < n; ++i) a[i + 1] = X[i]; for(int i = 0; i < m; ++i) b[i + 1] = Y[i]; sort(a + 1, a + 1 + n, [&](int a, int b) { return a > b; }); sort(b + 1, b + 1 + m, [&](int a, int b) { return a > b; }); for(int i = 0; i < t; ++i) s[i + 1] = {S[i], W[i]}; sort(s + 1, s + 1 + t, [&](pii a, pii b) { return a > b; }); int l = 1, r = t, res = -1; while(l <= r) { int mid = l + r >> 1; if(check(mid)) r = mid - 1, res = mid; else l = mid + 1; } return res; } #define fail(s, x...) do { \ fprintf(stderr, s "\n", ## x); \ exit(1); \ } while(0) #define MAX_A 50000 #define MAX_B 50000 #define MAX_T 500000 static int X[MAX_A]; static int Y[MAX_B]; static int W[MAX_T]; static int S[MAX_T]; int main() { int A, B, T, i; int res; FILE *f = fopen("input.txt", "r"); if (!f) fail("Failed to open input file."); res = fscanf(f, "%d", &A); if (res != 1) fail("Failed to read A from input file."); if (A < 0 || A > MAX_A) fail("A is out of bounds."); res = fscanf(f, "%d", &B); if (res != 1) fail("Failed to read B from input file."); if (B < 0 || B > MAX_B) fail("B is out of bounds."); res = fscanf(f, "%d", &T); if (res != 1) fail("Failed to read T from input file."); if (T < 1 || T > MAX_T) fail("T is out of bounds."); for (i = 0; i < A; i++) { res = fscanf(f, "%d", &X[i]); if (res != 1) fail("Failed to read data from input file."); } for (i = 0; i < B; i++) { res = fscanf(f, "%d", &Y[i]); if (res != 1) fail("Failed to read data from input file."); } for (i = 0; i < T; i++) { res = fscanf(f, "%d%d", &W[i], &S[i]); if (res != 2) fail("Failed to read data from input file."); } fclose(f); int answer = putaway(A, B, T, X, Y, W, S); printf("%d\n", answer); return 0; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:125:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
/tmp/cc1x2aG6.o: In function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccTZ5zLd.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status