답안 #614190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614190 2022-07-30T21:30:31 Z NK_ Self Study (JOI22_ho_t2) C++17
100 / 100
290 ms 11464 KB
#include <bits/stdc++.h>

using namespace std;

/////////////////////// MACROS ////////////////////////////////////////////
using ll = long long;
using ld = long double;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<str>;
using vc = vector<char>;
using vpi = vector<pi>;
using vpl = vector<pl>;


#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcTU> using PR = pair<T,U>;
tcTU> using umap = unordered_map<T, U>;
tcT> using uset = unordered_set<T>;
tcT> using mset = multiset<T>;

#define mp make_pair
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define ppb pop_back()
#define ppf pop_front()
#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

// LOOPS
#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 rep(a) F0R(_, a)
#define each(a,x) for (auto& a: x)

/////////////////////// IMPORANT VARS /////////////////////////////////////

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INFL = ll(2e18)+10;
const int INF = int(1e9)+10;
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
tcT> using pql = priority_queue<T,vector<T>,less<T>>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define nl '\n'

constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { 
	return x == 0 ? 0 : 31-__builtin_clz(x); }
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
 
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
 
tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
 
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true 
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	} 
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(it); } // element that doesn't exist from (multi)set


// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

// tcT> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// #define ook order_of_key
// #define fbo find_by_order

// struct chash { 
// 	const uint64_t C = ll(2e18*PI)+71;
// 	const int RANDOM = rng();
// 	ll operator()(ll x) const {
// 		return __builtin_bswap64((x^RANDOM)*C); }
// };
// template<class K,class V> using um = unordered_map<K,V,chash>;
// template<class K,class V> using ht = gp_hash_table<K,V,chash>;
// template<class K,class V> V get(ht<K,V>& u, K x) {
// 	auto it = u.find(x); return it == end(u) ? 0 : it->s; }

/////////////////////// OUPUT /////////////////////////////////////////////
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.f)+", "+ts(p.s)+")";
	#else
		return ts(p.f)+" "+ts(p.s);
	#endif
}

tcTU> str ts(V<pair<T, U>> v) {
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}

tcT> str ts(T v) {
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;

	#endif
}

///////////////////////// DEBUG ///////////////////////////////////////////
#define tcTUU tcT, class ...U
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
	cerr << ts(t); if (sizeof...(u)) cerr << ", ";
	DBG(u...); }
#ifdef LOCAL
	#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
	#define dbg(...) 0
	#define chk(...) 0
#endif

///////////////////////// FILE I/O ////////////////////////////////////////
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setPrec() { cout << fixed << setprecision(15); }
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
	unsyncIO(); setPrec();
	#ifndef LOCAL	
		if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
	#endif
}

///////////////////////// TEMPLATE ABOVE //////////////////////////////////

// REMEMBER
// - Don't Focus On Only One Approach
// - Read And Understand Problem Fully
// - Think Of Edges Cases
// - Implement Carefully
// - Always Check For Overflows
// - Reset Global Variables
// - Look At The Bigger Picture
// - Don't Get Discouraged, You Can Pull It Back

void solve() {
	int N; ll M; cin >> N >> M;
	vl A(N); each(x, A) cin >> x;
	vl B(N); each(x, B) cin >> x;

	F0R(i, N) ckmax(A[i], B[i]);	
	ll ans = lstTrue(1LL, INFL, [&](ll mn) {
		ll ex = 0;

		F0R(i, N) {
			ll t = (mn + A[i] - 1) / A[i];
			if (t <= M) ex += M - t;
			else {	
				ll left = mn - (M * A[i]);
				assert(left > 0);
				ll need = (left + B[i] - 1) / B[i];
				// dbg(i, mn, left, need, A[i], B[i]);
				ex -= need;
				if (ex > (N * 1LL * M)) return false;
			}
		}
		dbg(mn, ex);

		return ex >= 0;
	});
	cout << ans << nl;

}

int main() {
	setIO(); 

	int TT = 1;
	// cin >> TT;

	rep(TT) solve();
	
	exit(0-0);
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:195:19: warning: statement has no effect [-Wunused-value]
  195 |  #define dbg(...) 0
      |                   ^
Main.cpp:244:3: note: in expansion of macro 'dbg'
  244 |   dbg(mn, ex);
      |   ^~~
Main.cpp: In function 'void setIn(str)':
Main.cpp:202:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  202 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setOut(str)':
Main.cpp:203:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  203 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 5 ms 340 KB Output is correct
11 Correct 228 ms 5012 KB Output is correct
12 Correct 238 ms 5016 KB Output is correct
13 Correct 252 ms 5012 KB Output is correct
14 Correct 209 ms 5008 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 273 ms 6104 KB Output is correct
17 Correct 290 ms 11464 KB Output is correct
18 Correct 241 ms 10808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 273 ms 6104 KB Output is correct
3 Correct 290 ms 11464 KB Output is correct
4 Correct 241 ms 10808 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 122 ms 2660 KB Output is correct
14 Correct 80 ms 1876 KB Output is correct
15 Correct 61 ms 1492 KB Output is correct
16 Correct 53 ms 1236 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 5 ms 340 KB Output is correct
11 Correct 228 ms 5012 KB Output is correct
12 Correct 238 ms 5016 KB Output is correct
13 Correct 252 ms 5012 KB Output is correct
14 Correct 209 ms 5008 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 122 ms 2660 KB Output is correct
24 Correct 80 ms 1876 KB Output is correct
25 Correct 61 ms 1492 KB Output is correct
26 Correct 53 ms 1236 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 5 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 273 ms 6104 KB Output is correct
36 Correct 290 ms 11464 KB Output is correct
37 Correct 241 ms 10808 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 320 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 5 ms 468 KB Output is correct
46 Correct 9 ms 596 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 46 ms 2136 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 4 ms 468 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 324 KB Output is correct
54 Correct 1 ms 324 KB Output is correct
55 Correct 121 ms 5520 KB Output is correct
56 Correct 85 ms 3032 KB Output is correct
57 Correct 76 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 122 ms 2660 KB Output is correct
10 Correct 80 ms 1876 KB Output is correct
11 Correct 61 ms 1492 KB Output is correct
12 Correct 53 ms 1236 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 5 ms 340 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 273 ms 6104 KB Output is correct
22 Correct 290 ms 11464 KB Output is correct
23 Correct 241 ms 10808 KB Output is correct
24 Correct 42 ms 1952 KB Output is correct
25 Correct 111 ms 5020 KB Output is correct
26 Correct 26 ms 1364 KB Output is correct
27 Correct 244 ms 10812 KB Output is correct
28 Correct 256 ms 10828 KB Output is correct
29 Correct 244 ms 10808 KB Output is correct
30 Correct 255 ms 10824 KB Output is correct
31 Correct 245 ms 10772 KB Output is correct
32 Correct 252 ms 6144 KB Output is correct
33 Correct 254 ms 11460 KB Output is correct
34 Correct 273 ms 6188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 5 ms 340 KB Output is correct
11 Correct 228 ms 5012 KB Output is correct
12 Correct 238 ms 5016 KB Output is correct
13 Correct 252 ms 5012 KB Output is correct
14 Correct 209 ms 5008 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 122 ms 2660 KB Output is correct
24 Correct 80 ms 1876 KB Output is correct
25 Correct 61 ms 1492 KB Output is correct
26 Correct 53 ms 1236 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 5 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 328 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 320 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 9 ms 596 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 46 ms 2136 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 4 ms 468 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 324 KB Output is correct
50 Correct 1 ms 324 KB Output is correct
51 Correct 121 ms 5520 KB Output is correct
52 Correct 85 ms 3032 KB Output is correct
53 Correct 76 ms 3156 KB Output is correct
54 Correct 42 ms 1952 KB Output is correct
55 Correct 111 ms 5020 KB Output is correct
56 Correct 26 ms 1364 KB Output is correct
57 Correct 244 ms 10812 KB Output is correct
58 Correct 256 ms 10828 KB Output is correct
59 Correct 244 ms 10808 KB Output is correct
60 Correct 255 ms 10824 KB Output is correct
61 Correct 245 ms 10772 KB Output is correct
62 Correct 252 ms 6144 KB Output is correct
63 Correct 254 ms 11460 KB Output is correct
64 Correct 273 ms 6188 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 273 ms 6104 KB Output is correct
67 Correct 290 ms 11464 KB Output is correct
68 Correct 241 ms 10808 KB Output is correct
69 Correct 29 ms 1364 KB Output is correct
70 Correct 8 ms 596 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 38 ms 1812 KB Output is correct
73 Correct 9 ms 644 KB Output is correct
74 Correct 1 ms 336 KB Output is correct
75 Correct 245 ms 10736 KB Output is correct
76 Correct 248 ms 10808 KB Output is correct
77 Correct 245 ms 10840 KB Output is correct
78 Correct 272 ms 10760 KB Output is correct
79 Correct 260 ms 10808 KB Output is correct
80 Correct 258 ms 10808 KB Output is correct
81 Correct 237 ms 8708 KB Output is correct
82 Correct 241 ms 8836 KB Output is correct