feat: usaco
This commit is contained in:
parent
7795f9e52f
commit
bf585a88f9
26 changed files with 770 additions and 84 deletions
|
|
@ -76,13 +76,9 @@ void solve() {
|
|||
|
||||
a[0] = min(a[0], x - a[0]);
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (a[i] >= a[i - 1] && x - a[i] >= a[i - 1]) {
|
||||
if (x - a[i] >= a[i - 1]) {
|
||||
a[i] = min(a[i], x - a[i]);
|
||||
} else if (a[i] >= a[i - 1]) {
|
||||
;
|
||||
} else if (x - a[i] >= a[i - 1]) {
|
||||
a[i] = x - a[i];
|
||||
} else {
|
||||
} else if (a[i] < a[i - 1]) {
|
||||
prln("NO");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
93
codeforces/1020/f.cc
Normal file
93
codeforces/1020/f.cc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using d64 = double;
|
||||
using d128 = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pai = std::pair<T1, T2>;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
// NOTE: thought could loop thru the entire thing
|
||||
// knew memory was O(n^2), but didn't actually say:
|
||||
// ok what do i want to do - loop thru. this is impractical
|
||||
string prev(n, '1');
|
||||
// union_find<u64> uf;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (i)
|
||||
s[i] = ('0' + 1 - (s[i] - '0'));
|
||||
s[i] = ('0' + 1 - (s[i] - '0'));
|
||||
cout << "i: " << i << endl;
|
||||
cout << s << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (int t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/1020/io/f.in
Normal file
13
codeforces/1020/io/f.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
000
|
||||
4
|
||||
0010
|
||||
7
|
||||
1011001
|
||||
4
|
||||
0001
|
||||
2
|
||||
11
|
||||
1
|
||||
0
|
||||
24
codeforces/1020/io/f.out
Normal file
24
codeforces/1020/io/f.out
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
100
|
||||
010
|
||||
001
|
||||
1010
|
||||
0110
|
||||
0000
|
||||
0011
|
||||
0011001
|
||||
1111001
|
||||
1001001
|
||||
1010001
|
||||
1011101
|
||||
1011011
|
||||
1011000
|
||||
1001
|
||||
0101
|
||||
0011
|
||||
0000
|
||||
01
|
||||
10
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.11367 ms
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(x) for (size_t i = 0; i < (x).size(); ++i)
|
||||
|
||||
#ifndef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << (x) << '\n'
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define PROBLEM_NAME "blocks"
|
||||
|
||||
void solve() {
|
||||
int N;
|
||||
cin >> N;
|
||||
vector<int> ans(26, 0);
|
||||
|
||||
for(int i = 0; i < N; ++i) {
|
||||
string left, right;
|
||||
cin >> left >> right;
|
||||
vector<int> count_left(26, 0);
|
||||
for(char c : left) count_left[c - 'a']++;
|
||||
vector<int> count_right(26, 0);
|
||||
for(char c : right) count_right[c - 'a']++;
|
||||
for(int j = 0; j < 26; ++j) {
|
||||
ans[j] += max(count_left[j], count_right[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int count : ans) {
|
||||
cout << count << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
3
|
||||
fox box
|
||||
dog cat
|
||||
car bus
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
2
|
||||
2
|
||||
2
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
2
|
||||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
9
usaco/bronze/.clang-format
Normal file
9
usaco/bronze/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
30
usaco/bronze/compile_flags.txt
Normal file
30
usaco/bronze/compile_flags.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
12
usaco/bronze/debug_flags.txt
Normal file
12
usaco/bronze/debug_flags.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
-g3
|
||||
-fsanitize=address,undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fno-sanitize-recover=all
|
||||
-fstack-protector-all
|
||||
-fstack-usage
|
||||
-fno-omit-frame-pointer
|
||||
-fno-inline
|
||||
-ffunction-sections
|
||||
-D_GLIBCXX_DEBUG
|
||||
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||
3
usaco/bronze/io/mixmilk.in
Normal file
3
usaco/bronze/io/mixmilk.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
10 3
|
||||
11 4
|
||||
12 5
|
||||
6
usaco/bronze/io/mixmilk.out
Normal file
6
usaco/bronze/io/mixmilk.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
0
|
||||
10
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.47321 ms
|
||||
7
usaco/bronze/io/rut.in
Normal file
7
usaco/bronze/io/rut.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
E 3 5
|
||||
N 5 3
|
||||
E 4 6
|
||||
E 10 4
|
||||
N 11 2
|
||||
N 8 1
|
||||
9
usaco/bronze/io/rut.out
Normal file
9
usaco/bronze/io/rut.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
5
|
||||
3
|
||||
Infinity
|
||||
Infinity
|
||||
2
|
||||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8356 ms
|
||||
4
usaco/bronze/io/shell-game.in
Normal file
4
usaco/bronze/io/shell-game.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
1 2 1
|
||||
3 2 1
|
||||
1 3 1
|
||||
4
usaco/bronze/io/shell-game.out
Normal file
4
usaco/bronze/io/shell-game.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.1527 ms
|
||||
7
usaco/bronze/io/speeding.in
Normal file
7
usaco/bronze/io/speeding.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3 3
|
||||
40 75
|
||||
50 35
|
||||
10 45
|
||||
40 76
|
||||
20 30
|
||||
40 40
|
||||
4
usaco/bronze/io/speeding.out
Normal file
4
usaco/bronze/io/speeding.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.50397 ms
|
||||
27
usaco/bronze/makefile
Normal file
27
usaco/bronze/makefile
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
.PHONY: run debug clean setup init
|
||||
|
||||
SRC = $(word 2,$(MAKECMDGOALS))
|
||||
|
||||
.SILENT:
|
||||
|
||||
run:
|
||||
sh scripts/run.sh $(SRC)
|
||||
|
||||
debug:
|
||||
sh scripts/debug.sh $(SRC)
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
|
||||
setup:
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
test -d scripts || mkdir -p scripts
|
||||
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt .
|
||||
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
|
||||
|
||||
init:
|
||||
make setup
|
||||
|
||||
%:
|
||||
@:
|
||||
90
usaco/bronze/mixmilk.cc
Normal file
90
usaco/bronze/mixmilk.cc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
vector<u64> c(3), m(3);
|
||||
for (u32 i = 0; i < 3; ++i) {
|
||||
cin >> c[i] >> m[i];
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < 100; ++i) {
|
||||
u64 pour = min(m[i % 3], c[(i + 1) % 3] - m[(i + 1) % 3]);
|
||||
m[i % 3] -= pour;
|
||||
m[(i + 1) % 3] += pour;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < 3; ++i) {
|
||||
cout << m[i] << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "mixmilk"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
112
usaco/bronze/rut.cc
Normal file
112
usaco/bronze/rut.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
struct Cow {
|
||||
u32 i;
|
||||
i64 x, y;
|
||||
};
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vector<Cow> east_cows, north_cows;
|
||||
vector<i64> ans(n, -1);
|
||||
|
||||
char dir;
|
||||
i64 x, y;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> dir >> x >> y;
|
||||
|
||||
Cow cow{i, x, y};
|
||||
if (dir == 'E') {
|
||||
east_cows.emplace_back(cow);
|
||||
} else {
|
||||
north_cows.emplace_back(cow);
|
||||
}
|
||||
}
|
||||
|
||||
sort(all(east_cows), [](auto const& c1, auto const& c2) {
|
||||
return c1.y < c2.y;
|
||||
});
|
||||
sort(all(north_cows), [](auto const& c1, auto const& c2) {
|
||||
return c1.x < c2.x;
|
||||
});
|
||||
|
||||
for (auto& nc : north_cows) {
|
||||
for (auto& ec : east_cows) {
|
||||
if (ec.x > nc.x || nc.y >= ec.y || ans[ec.i] != -1)
|
||||
continue;
|
||||
|
||||
auto et = nc.x - ec.x;
|
||||
auto nt = ec.y - nc.y;
|
||||
|
||||
if (nt < et) {
|
||||
ans[ec.i] = et;
|
||||
}
|
||||
if (et < nt) {
|
||||
ans[nc.i] = nt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& e : ans) {
|
||||
if (e == -1) {
|
||||
cout << "Infinity";
|
||||
} else {
|
||||
cout << e;
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "rut"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
29
usaco/bronze/scripts/debug.sh
Normal file
29
usaco/bronze/scripts/debug.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
DBG_BIN="${BASE}.debug"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
DBG_BIN="build/$DBG_BIN"
|
||||
|
||||
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
29
usaco/bronze/scripts/run.sh
Normal file
29
usaco/bronze/scripts/run.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
RUN_BIN="${BASE}.run"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
RUN_BIN="build/$RUN_BIN"
|
||||
|
||||
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
53
usaco/bronze/scripts/utils.sh
Normal file
53
usaco/bronze/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
CODE=$?
|
||||
end=$(date '+%s.%N')
|
||||
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||
|
||||
if [ $CODE -ge 124 ]; then
|
||||
MSG=''
|
||||
case $CODE in
|
||||
124) MSG='TIMEOUT' ;;
|
||||
128) MSG='SIGILL' ;;
|
||||
130) MSG='SIGABRT' ;;
|
||||
131) MSG='SIGBUS' ;;
|
||||
136) MSG='SIGFPE' ;;
|
||||
135) MSG='SIGSEGV' ;;
|
||||
137) MSG='SIGPIPE' ;;
|
||||
139) MSG='SIGTERM' ;;
|
||||
esac
|
||||
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||
else
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
fi
|
||||
|
||||
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||
return $CODE
|
||||
}
|
||||
|
||||
compile_source() {
|
||||
src="$1"
|
||||
bin="$2"
|
||||
output="$3"
|
||||
flags="$4"
|
||||
|
||||
test -f "$bin" && rm "$bin" || true
|
||||
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||
CODE=$?
|
||||
|
||||
if [ $CODE -gt 0 ]; then
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
return $CODE
|
||||
else
|
||||
echo '' >"$output"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
97
usaco/bronze/shell.cc
Normal file
97
usaco/bronze/shell.cc
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
vector<u32> shell_locs(3), shell_counts(3, 0);
|
||||
iota(all(shell_locs), 0);
|
||||
|
||||
u32 n, a, b, g;
|
||||
cin >> n;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a >> b >> g;
|
||||
|
||||
--a;
|
||||
--b;
|
||||
--g;
|
||||
for (u32 j = 0; j < shell_locs.size(); ++j) {
|
||||
if (shell_locs[j] == a)
|
||||
shell_locs[j] = b;
|
||||
else if (shell_locs[j] == b)
|
||||
shell_locs[j] = a;
|
||||
shell_counts[j] += shell_locs[j] == g;
|
||||
}
|
||||
}
|
||||
|
||||
cout << *max_element(all(shell_counts)) << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "shell"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
106
usaco/bronze/speeding.cc
Normal file
106
usaco/bronze/speeding.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vector<pair<i32, i32>> limit(n), cow(m);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> limit[i].ff >> limit[i].ss;
|
||||
if (i)
|
||||
limit[i].ff += limit[i - 1].ff;
|
||||
}
|
||||
for (u32 i = 0; i < m; ++i) {
|
||||
cin >> cow[i].ff >> cow[i].ss;
|
||||
if (i)
|
||||
cow[i].ff += cow[i - 1].ff;
|
||||
}
|
||||
|
||||
i32 i = -1, j = -1;
|
||||
|
||||
i32 ans = 0;
|
||||
while (j < m) {
|
||||
if (i == -1) {
|
||||
++i;
|
||||
++j;
|
||||
} else if (i + 1 < n && limit[i + 1].ff <= cow[j].ff) {
|
||||
++i;
|
||||
} else {
|
||||
++j;
|
||||
}
|
||||
ans = max(ans, cow[j].ss - limit[i].ss);
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "speeding"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue