Compare commits

..

13 Commits

Author SHA1 Message Date
5d8efe99be complete 1183.cpp 1190.cpp 1929.cpp 2026-07-10 15:25:46 +09:00
1a69d9b1e9 improve cpp tempalte 2026-07-10 14:29:04 +09:00
b737eca173 complete jungol//2194.cpp and fix it 2026-07-10 13:41:41 +09:00
8c0d172f36 complete jungol/3521.cpp jungol/4520.cpp qoj/1.cpp 2026-06-26 20:02:25 +09:00
5a14bd0d2d add some 2026-06-26 18:42:29 +09:00
bc1489d320 complete ojuz/KAISTRUN26SPRING_A.cpp 2026-05-08 15:57:19 +09:00
cfb65a4c2d complete jungol/1000.rs 2026-05-06 18:19:34 +09:00
8f0ec6cead hotfix run.py run 2026-05-06 18:11:19 +09:00
be454e4420 Merge branch 'dev' 2026-05-06 18:00:46 +09:00
3e69d7713e rename aloha feat 2026-05-04 15:03:11 +09:00
d1720c1567 rename invalid name in contest 2026-05-04 15:01:08 +09:00
d6777983a1 migrate small contest 2026-05-04 14:59:37 +09:00
cac746a69c add 2026-kaist-run-spring 2026-05-03 18:45:47 +09:00
54 changed files with 1032 additions and 6 deletions

7
run.py
View File

@@ -644,12 +644,10 @@ def run(lang: str, testcase: tuple[str, ...], verbose: bool):
f_in_path = f"{TC_DIR}/{tc}.in"
f_out_path = f"{TC_DIR}/{tc}.out"
with (
open(f_in_path, "r", encoding="utf-8") as f_in,
open(f_out_path, "r", encoding="utf-8") as f_out,
):
with open(f_out_path, "r", encoding="utf-8") as f_out:
expected = f_out.read().strip()
f_in = open(f_in_path, "r", encoding="utf-8")
proc = subprocess.Popen(
target_language.executable_command,
stdin=f_in,
@@ -663,6 +661,7 @@ def run(lang: str, testcase: tuple[str, ...], verbose: bool):
print(line, end="")
stdout, stderr = proc.communicate()
f_in.close()
if proc.returncode != 0:
click.secho(">>>>>> [RUN TIME ERROR] >>>>>>", fg="red", bold=True)

View File

@@ -0,0 +1,63 @@
#include <iostream>
#include <algorithm>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
const usize MOD = 1'000'000'007;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
/**
*
* If there is energy x phage
* f(1, x) = f(2, x + 1) + f(2, x - 1)
* 0 0 0 1 0 0 0 0 0
* 0 0 1 0 1 2
* 0 1 0 2 0 0 0 0
* 1 0 3 0 3 0 0 0 8
* 0 4 0
* 4 0 10 0 10
* 0 14 0 20
* 14 0 34 35 119
* 48 68
*/
/**
* 1
* 1 1
* 1 2 1
* 1 3 3 1
* 1 4 6 4 1
* 1 5 10 10 5 1
* 1 6 15 20 15 6 1
* 1 7 21 35 35
*
* 48
*
*
*
* 1 4 10+4 14+14+20 14+20+
*/
// 10 4일 때
// 1 2 4 8 15 30
// 0 1 2 3 4 5 6 7 8 9
fn main() -> int {
fastio();
usize k, n;
usize col1 = 0;
usize col2 = 0;
cin >> k >> n;
}

View File

@@ -0,0 +1,52 @@
#include <iostream>
#include <algorithm>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
const usize MOD = 1'000'000'007;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
/**
*
*/
fn main() -> int {
usize t;
usize n;
usize k;
usize ret;
cout << (1 ^ 2) << endl;
return 0;
cin >> t;
/**
*
* xor0이 가능한 클러스터 X1, X2에 대해서
* X1과 X2를 연결한 클러스터 X1-X2도 동일한 속성을 만족하는 클러스터임.
* xor0이 가능한 최소 클러스터 크기는 1임
* 1
* { 1 2 3 }이 가능한클러스터군... 죽고 싶다
* { 0, 0 } {1, 1}, {2, 2} (자유도 만큼) k + 1
* {0, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}, {0, 2, 2}, {1, 1, 0}, 3 * k + 1
* { 0011 } {0022} {0033} {1122} {1133} {2233} {0000}{1111}{2222}{3333}
*/
while (t--) {
cin >> n >> k;
if (k == 0) {
ret = 1;
} else {
}
cout << ret << "\n";
}
}

View File

@@ -0,0 +1,95 @@
#include <algorithm>
#include <iostream>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
struct Node {
usize acc;
usize self;
vector<Node *> *adjs;
void add_route(Node *node) {
adjs->push_back(node);
}
void update_delta(usize delta) {
acc += delta;
self += delta;
for (let x: *adjs) {
x->update_by_direct(delta);
}
}
void update_by_direct(usize delta) {
acc += delta;
}
};
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
fastio();
usize n, q;
cin >> n >> q;
let arr = (usize *) calloc(n, sizeof(usize));
let graph = (Node **) calloc(n, sizeof(Node *));
for (usize i = 0; i < n; i++) {
graph[i] = (Node *) malloc(sizeof(Node));
graph[i]->acc = 0;
graph[i]->self = 0;
graph[i]->adjs = new vector<Node *>();
}
for (usize i = 0; i < n; i++) {
usize a;
cin >> a;
arr[i] = a;
}
for (usize i = 0; i < n - 1; i++) {
usize u, v;
cin >> u >> v;
u = u - 1;
v = v - 1;
graph[u]->add_route(graph[v]);
graph[v]->add_route(graph[u]);
}
for (usize i = 0; i < n; i++) {
graph[i]->update_delta(arr[i]);
}
for (usize i = 0; i < q; i++) {
usize inst;
cin >> inst;
if (inst == 1) {
usize target, c;
cin >> target >> c;
target -= 1;
graph[target]->update_delta(c);
} else {
usize target;
cin >> target;
target -= 1;
cout << graph[target]->acc << '\n';
}
}
end:
free(arr);
for (usize i = 0; i < n; i++) {
delete graph[i]->adjs;
free(graph[i]);
}
free(graph);
}

View File

@@ -0,0 +1,72 @@
#include <algorithm>
#include <iostream>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
const usize MOD = 1'000'000'007;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn count_ilove(usize x, const vector<usize> &hates) -> usize {
if (x == 0) return 0;
string s = to_string(x);
usize n = s.size();
vector<vector<vector<usize>>> dp(n + 1,
vector<vector<usize>>(2, vector<usize>(2, 0)));
dp[0][1][0] = 1;
for (usize pos = 0; pos < n; pos++) {
for (usize tight = 0; tight <= 1; tight++) {
for (usize started = 0; started <= 1; started++) {
usize limit = tight ? (s[pos] - '0') : 9;
for (usize digit = 0; digit <= limit; digit++) {
bool is_hated = false;
for (usize h: hates) {
if (h == digit) {
is_hated = true;
break;
}
}
if (is_hated) continue;
bool next_started = started || (digit != 0);
usize next_tight = (tight && digit == limit) ? 1 : 0;
if (!next_started && pos == n - 1) continue;
dp[pos + 1][next_tight][next_started] += dp[pos][tight][started];
}
}
}
}
usize result = 0;
for (usize tight = 0; tight <= 1; tight++) {
result += dp[n][tight][1];
}
return result;
}
fn main() -> int {
fastio();
usize n, l, r;
cin >> n >> l >> r;
vector<usize> hates(n);
for (usize i = 0; i < n; i++) {
cin >> hates[i];
}
usize ret = (count_ilove(r, hates) + 2 * MOD - (count_ilove(l - 1, hates))) % MOD;
cout << ret % MOD << "\n";
}

View File

@@ -0,0 +1,103 @@
#include <algorithm>
#include <iostream>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
#define UD 1'000'000
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
fastio();
usize n, m;
cin >> n >> m;
let arr = new usize[5 * m];
let music = new usize[n];
let cnts = new usize[n];
for (usize i = 0; i < n; i++) {
music[i] = UD;
cnts[i] = 0;
}
for (usize i = 0; i < m; i++) {
for (usize j = 0; j < 4; j++) {
cin >> arr[5 * i + j];// idx
arr[5 * i + j] -= 1;
cnts[arr[5 * i + j]]++;
}
cin >> arr[5 * i + 4];
}
let cntv = vector<pair<usize, usize>>();
for (usize i = 0; i < n; i++) {
cntv.push_back(pair(cnts[i], i));
}
sort(cntv.begin(), cntv.end());
reverse(cntv.begin(), cntv.end());
usize tot = 0;
usize before = 0;
for (let it = cntv.begin(); it < cntv.end(); it++) {
if (tot > 3 * m) {
music[before] = UD;
break;
} else if (tot == 3 * m) {
break;
}
else {
tot += it->first;
music[it->second] = 0;
before = it->second;
}
}
for (usize i = 0; i < m; i++) {
let x = arr[5 * i + 0];
let y = arr[5 * i + 1];
let z = arr[5 * i + 2];
let w = arr[5 * i + 3];
let k = arr[5 * i + 4];
let mx = music[x];
let my = music[y];
let mz = music[z];
let mw = music[w];
let key = (mx % 4 + my % 4 + mz % 4 + mw % 4) % 4;
if ((mx + my + mz + mw) / UD == 1) {
if (mx == UD) {
music[x] = (k + 4 - key) % 4;
} else if (my == UD) {
music[y] = (k + 4 - key) % 4;
} else if (mz == UD) {
music[z] = (k + 4 - key) % 4;
} else {
music[w] = (k + 4 - key) % 4;
}
}
}
for (usize i = 0; i < n; i++) {
if (music[i] == UD) {
music[i] = 0;
}
}
for (usize i = 0; i < n; i++) {
cout << music[i] << " ";
}
delete[] arr;
delete[] music;
delete[] cnts;
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <algorithm>
#include <iostream>
#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 r, u, n;
cin >> r >> u >> n;
usize cnt = r * u;
if (n <= 10) {
usize fibn = 2;
usize fibns1 = 1;
usize fibns2 = 1;
for (usize i = 3; i < n; i++) {
fibns2 = fibns1;
fibns1 = fibn;
fibn = fibns2 + fibns1;
}
usize delta = ((u - 1) * fibns1 + (r - 1) * fibns2);
cout << delta / fibns1 + delta / fibns2 - (delta / (fibns1 * fibns2)) + 1 << endl;
} else {
cout << cnt << endl;
}
}

View File

@@ -0,0 +1,80 @@
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
#define UMAX 0xfffffff
using namespace std;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
struct Fire {
usize f;
usize v;
};
fn main() -> int {
fastio();
let _comp = [](Fire &a, const Fire &b) { return a.f < b.f; };
usize n, m;
cin >> n >> m;
let fs = vector<Fire>(n);
let bs = vector<usize>(m);
for (usize i = 0; i < n; i++) {
cin >> fs[i].f;
cin >> fs[i].v;
}
sort(fs.begin(), fs.end(), _comp);
for (usize i = 0; i < m; i++) {
cin >> bs[i];
}
// 1pass
usize last = UMAX;
let vfx = vector<usize>();
for (usize i = 0; i < m; i++) {
let t = bs[i];
Fire tf = {
.f = t,
.v = 0,
};
}
if (last == UMAX) {
last = m;
}
// 2pass
sort(vfx.begin(), vfx.end());
let heap = priority_queue<usize>();
usize total_v = 0;
while (vfx.size() > 0) {
let key = *(vfx.end() - 1);
vfx.pop_back();
while (fs.size() > 0 && (fs.end() - 1)->f >= key) {
heap.push((fs.end() - 1)->v);
fs.pop_back();
}
total_v += heap.top();
heap.pop();
}
cout << last << " " << total_v << endl;
}

View 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;
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,43 @@
#include <algorithm>
#include <iostream>
#include <vector>
#define let auto
#define fn auto
#define usize size_t
using namespace std;
#define LIMIT (((usize) 1 << 63) - 1);
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
fastio();
usize n, s;
cin >> n >> s;
let costs = vector<usize>(n);
let yopps = vector<usize>(n);
// it needs cost S for storing 1 litre of milk for a week.
let cummin = vector<usize>(n);
for (usize i = 0; i < n; i++) {
cin >> costs[i] >> yopps[i];
}
let curr_min = (usize) LIMIT;
for (usize i = 0; i < n; i++) {
curr_min = min(curr_min + s, costs[i]);
cummin[i] = curr_min;
}
let total = (usize) 0;
for (usize i = 0; i < n; i++) {
total += cummin[i] * yopps[i];
}
cout << total << endl;
}

View File

@@ -0,0 +1,47 @@
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdint>
#define let auto
#define fn auto
#define usize size_t
#define u64 uint64_t
using namespace std;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
fastio();
let grams = vector<u64>{1, 2, 4, 8, 16};
let counts = vector<u64>(5);
for (usize i = 0; i < 5; i++) {
cin >> counts[i];
}
usize n;
cin >> n;
let usage = 0;
let i = 4;
while (i >= 0 && n > 0) {
if (counts[i] > 0 && n >= grams[i]) {
n -= grams[i];
counts[i] -= 1;
usage += 1;
} else {
i--;
}
}
if (n != 0) {
cout << "impossible" << endl;
} else {
cout << usage << endl;
}
}

View File

@@ -0,0 +1,50 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#define let auto
#define fn auto
typedef size_t usize;
using namespace std;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
usize n, k;
cin >> n >> k;
let line = vector<char>(n);
let valid = vector<bool>(n, false);
for (usize i = 0; i < n; i++) {
char t;
cin >> t;
line[i] = t;
if (t == 'H') {
valid[i] = true;
}
}
// left assoc
let count = 0;
for (usize i = 0; i < n; i++) {
if (line[i] == 'P') {
let left = i >= k ? i - k : 0;
let right = i + k >= n ? n - 1 : i + k;
for (usize j = left; j <= right; j++) {
if (valid[j]) {
count += 1;
valid[j] = false;
break;
}
}
}
}
cout << count << endl;
}

View File

@@ -0,0 +1,13 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let a = iter.next().unwrap();
let b = iter.next().unwrap();
println!("{}", a + b);
}

View File

@@ -0,0 +1,27 @@
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>
:
#define let auto
#define fn auto
#define usize size_t
#define u64 uint64_t
#define i64 int64_t
using namespace std;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
fastio();
u64 r, u, n;
cin >> r >> u >> n;
// f(n-2) f(n-1) f(n)
// f(n-2) * r + f(n-1) * u
// 일정 이상의 n에 대해서 f(n-2)와 f(n-1)은 서로소임.
}

View File

@@ -0,0 +1,113 @@
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>
#define let auto
#define fn auto
#define usize size_t
using u32 = uint32_t;
using namespace std;
const u32 KX = 123456789;
const u32 KY = 362436069;
const u32 KZ = 521288629;
const u32 KW = 88675123;
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
struct Rand {
u32 x, y, z, w;
static Rand new_seed(u32 seed) {
return {KX ^ seed, KY ^ seed, KZ, KW};
}
u32 rand() {
u32 t = x ^ (x << 11);
x = y;
y = z;
z = w;
w ^= (w >> 19) ^ t ^ (t >> 8);
return w;
}
template<typename T>
void shuffle(vector<T>& a) {
if (a.empty()) return;
usize i = a.size() - 1;
while (i > 0) {
usize j = rand() % (i + 1);
swap(a[i], a[j]);
i--;
}
}
u32 rand_range(u32 a, u32 b) {
u32 m = b - a + 1;
return a + rand() % m;
}
double rand_float() {
return static_cast<double>(rand()) / static_cast<double>((u32)-1);
}
};
fn main() -> int {
fastio();
istreambuf_iterator<char> it(cin), end;
string temp(it, end);
vector<u32> vals;
usize pos = 0;
while (pos < temp.size()) {
while (pos < temp.size() && isspace(temp[pos])) pos++;
if (pos >= temp.size()) break;
usize start = pos;
while (pos < temp.size() && !isspace(temp[pos])) pos++;
vals.push_back(stoul(temp.substr(start, pos - start)));
}
auto it2 = vals.begin();
u32 n = *it2++;
u32 m = *it2++;
vector<tuple<u32, u32, u32, u32, u32>> requests;
for (u32 i = 0; i < m; i++) {
u32 w = *it2++ - 1;
u32 x = *it2++ - 1;
u32 y = *it2++ - 1;
u32 z = *it2++ - 1;
u32 k = *it2++;
requests.emplace_back(w, x, y, z, k);
}
u32 trial = 0;
while (true) {
Rand rand = Rand::new_seed(trial);
vector<u32> music(n);
for (u32 i = 0; i < n; i++) {
music[i] = rand.rand_range(0, 3);
}
u32 cnt = 0;
for (const auto& req : requests) {
u32 w, x, y, z, k;
tie(w, x, y, z, k) = req;
if ((music[w] + music[x] + music[y] + music[z]) % 4 == k) {
cnt++;
}
}
if (m / 4 <= cnt) {
for (u32 a : music) {
cout << a << ' ';
}
break;
}
trial++;
}
return 0;
}

39
storage/qoj/cpp/1.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include <algorithm>
#include <iostream>
#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);
}
#if 0
fn main() -> int {
fastio();
usize n, s = 0, t;
cin >> n;
for (usize i = 0; i < n; i++) {
cin >> t;
s += t;
}
cout << s << endl;
}
#else
fn main() -> int {
fastio();
usize k = 100'000'008;
usize n;
cin >> n;
for (usize i = 0; i < n; i++) {
cout << k << " ";
}
cout << endl;
}
#endif

View File

@@ -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();
}