This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353
void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s))
{
freopen((s + ".in").c_str(), "r", stdin);
if (s != "test1")
freopen((s + ".out").c_str(), "w", stdout);
}
}
#ifndef arwaeystoamneg
#include "robots.h";
#endif
const int MAX_N = 50005, MAX_K = 1000005;
int n, m, k, a[MAX_N], b[MAX_N];
pii c[MAX_K];
bitset<MAX_K>v;
int check(int co)
{
F0R(i, k)v[i] = 0;
// do y
map<int, ll>cur;
F0R(i, m)cur[b[i]] += co;
F0R(i, k)
{
auto it = cur.upper_bound(c[i].s);
if (it == cur.end())continue;
it->s--;
if (it->s == 0)cur.erase(it);
v[i] = 1;
}
cur.clear();
F0R(i, n)cur[a[i]] += co;
F0R(i, k)
{
if (v[i])continue;
auto it = cur.upper_bound(c[i].f);
if (it == cur.end())return 0;
it->s--;
if (it->s == 0)cur.erase(it);
}
return 1;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
n = A, m = B, k = T;
F0R(i, n)a[i] = X[i];
F0R(i, m)b[i] = Y[i];
F0R(i, k)c[i] = { W[i],S[i] };
sort(c, c + k, greater<pii>());
if (!check(inf))return -1;
int l = 1, r = inf;
while (l < r)
{
int mid = (l + r) / 2;
if (check(mid))r = mid;
else l = mid + 1;
}
return l;
}
#ifdef arwaeystoamneg
void fail(string s) {
cout << s << endl;
exit(1);
}
#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() {
setIO("");
int A, B, T, i;
int res = 1;
cin >> A;
if (res != 1)
fail("Failed to read A from input file.");
if (A < 0 || A > MAX_A)
fail("A is out of bounds.");
cin >> B;
if (res != 1)
fail("Failed to read B from input file.");
if (B < 0 || B > MAX_B)
fail("B is out of bounds.");
cin >> 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++) {
cin >> X[i];
if (res != 1)
fail("Failed to read data from input file.");
}
for (i = 0; i < B; i++) {
cin >> Y[i];
if (res != 1)
fail("Failed to read data from input file.");
}
res = 2;
for (i = 0; i < T; i++) {
cin >> W[i] >> S[i];
if (res != 2)
fail("Failed to read data from input file.");
}
int answer = putaway(A, B, T, X, Y, W, S);
cout << answer << endl;
return 0;
}
#endif
Compilation message (stderr)
robots.cpp:54:20: warning: extra tokens at end of #include directive
54 | #include "robots.h";
| ^
robots.cpp: In function 'void setIO(std::string)':
robots.cpp:48:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
48 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
robots.cpp:50:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
50 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |