Compare commits
2 Commits
b737eca173
...
5d8efe99be
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d8efe99be | |||
| 1a69d9b1e9 |
88
storage/jungol/cpp/completed/1183.cpp
Normal file
88
storage/jungol/cpp/completed/1183.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
using namespace std;
|
||||
|
||||
typedef size_t usize;
|
||||
typedef ssize_t isize;
|
||||
typedef int32_t i32;
|
||||
typedef u_int32_t u32;
|
||||
typedef int64_t i64;
|
||||
typedef u_int64_t u64;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
struct State {
|
||||
usize curr;
|
||||
usize w;
|
||||
vector<u64> pays;
|
||||
};
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
const usize N = 6;
|
||||
let coins = vector<u64>{500, 100, 50, 10, 5, 1};
|
||||
let counts = vector<u64>(N);
|
||||
|
||||
usize w;
|
||||
cin >> w;
|
||||
|
||||
for (let &v: counts) {
|
||||
cin >> v;
|
||||
}
|
||||
|
||||
let stack = vector<State>();
|
||||
let maxpays = vector<u64>(N, 0);
|
||||
let maxtotal = (u64) 0;
|
||||
stack.push_back({N - 1, w, vector<u64>(N, 0)});
|
||||
while (!stack.empty()) {
|
||||
let now = stack.back();
|
||||
stack.pop_back();
|
||||
|
||||
let curr = now.curr;
|
||||
if (curr == 0) {
|
||||
if (now.w % coins[curr] != 0) {
|
||||
continue;
|
||||
} else {
|
||||
now.pays[curr] = now.w / coins[curr];
|
||||
u64 total = accumulate(now.pays.begin(), now.pays.end(), 0);
|
||||
if (total > maxtotal) {
|
||||
maxpays = now.pays;
|
||||
maxtotal = total;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
let rem = now.w % coins[curr - 1] / coins[curr];
|
||||
let delta = coins[curr - 1] / coins[curr];
|
||||
if (counts[curr] < rem) {
|
||||
continue;
|
||||
}
|
||||
let maxto = (counts[curr] - rem) / delta;
|
||||
|
||||
for (usize i = 0; i <= maxto; i++) {
|
||||
let cst = (i * delta + rem) * coins[curr];
|
||||
if (cst > now.w) {
|
||||
break;
|
||||
}
|
||||
let newpay = now.pays;
|
||||
newpay[curr] = i * delta + rem;
|
||||
stack.push_back({curr - 1, now.w - cst, newpay});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << maxtotal << endl;
|
||||
for (let p: maxpays) {
|
||||
cout << p << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
52
storage/jungol/cpp/completed/1190.cpp
Normal file
52
storage/jungol/cpp/completed/1190.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
using namespace std;
|
||||
|
||||
typedef size_t usize;
|
||||
typedef ssize_t isize;
|
||||
typedef int32_t i32;
|
||||
typedef u_int32_t u32;
|
||||
typedef int64_t i64;
|
||||
typedef u_int64_t u64;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
|
||||
usize n;
|
||||
cin >> n;
|
||||
let lengths = vector<u64>(n);
|
||||
for (let &l: lengths) {
|
||||
cin >> l;
|
||||
}
|
||||
|
||||
let gt = std::greater<u64>();
|
||||
|
||||
make_heap(lengths.begin(), lengths.end(), gt);
|
||||
|
||||
u64 cost = 0;
|
||||
while (lengths.size() > 1) {
|
||||
pop_heap(lengths.begin(), lengths.end(), gt);
|
||||
let a = lengths.back();
|
||||
lengths.pop_back();
|
||||
|
||||
pop_heap(lengths.begin(), lengths.end(), gt);
|
||||
let b = lengths.back();
|
||||
lengths.pop_back();
|
||||
|
||||
cost += a + b;
|
||||
lengths.push_back(a + b);
|
||||
push_heap(lengths.begin(), lengths.end(), gt);
|
||||
}
|
||||
|
||||
cout << cost << endl;
|
||||
}
|
||||
47
storage/jungol/cpp/completed/1929.cpp
Normal file
47
storage/jungol/cpp/completed/1929.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
#define usize size_t
|
||||
using namespace std;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
|
||||
|
||||
usize n;
|
||||
cin >> n;
|
||||
let lengths = vector<usize>(n);
|
||||
for (let &l: lengths) {
|
||||
cin >> l;
|
||||
}
|
||||
|
||||
let gt = std::greater<usize>();
|
||||
|
||||
make_heap(lengths.begin(), lengths.end(), gt);
|
||||
|
||||
usize cost = 0;
|
||||
while (lengths.size() > 1) {
|
||||
pop_heap(lengths.begin(), lengths.end(), gt);
|
||||
let a = lengths.back();
|
||||
lengths.pop_back();
|
||||
|
||||
pop_heap(lengths.begin(), lengths.end(), gt);
|
||||
let b = lengths.back();
|
||||
lengths.pop_back();
|
||||
|
||||
cost += a + b;
|
||||
lengths.push_back(a + b);
|
||||
push_heap(lengths.begin(), lengths.end(), gt);
|
||||
}
|
||||
|
||||
cout << cost << endl;
|
||||
}
|
||||
@@ -1,17 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
#define usize size_t
|
||||
using namespace std;
|
||||
|
||||
typedef size_t usize;
|
||||
typedef ssize_t isize;
|
||||
typedef int32_t i32;
|
||||
typedef u_int32_t u32;
|
||||
typedef int64_t i64;
|
||||
typedef u_int64_t u64;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
|
||||
fastio();
|
||||
}
|
||||
Reference in New Issue
Block a user