Compare commits

..

12 Commits

Author SHA1 Message Date
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
b4dff1d344 fix StorageManager save, read expression and operation
fix create
fix export; not remove src space
2026-05-06 03:02:05 +09:00
b3cd28471e fix export command to clear space state 2026-05-06 02:53:30 +09:00
b15648a17c fix StateManager to save the state 2026-05-06 02:51:41 +09:00
bfb79e573d fix create 2026-05-06 02:40:41 +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
41 changed files with 372 additions and 18 deletions

45
run.py
View File

@@ -267,6 +267,15 @@ class StateManager:
with open(STATE_PATH, "w", encoding="utf-8") as f: with open(STATE_PATH, "w", encoding="utf-8") as f:
yaml.safe_dump(self._state, f) yaml.safe_dump(self._state, f)
@staticmethod
def _auto_save(func):
def wrapper(self, *args, **kwargs):
result = func(self, *args, **kwargs)
self.save()
return result
return wrapper
def check_space(self, lang: Language) -> bool: def check_space(self, lang: Language) -> bool:
state = self._load() state = self._load()
return lang.value in state.get("space", {}) and bool(state["space"][lang.value]) return lang.value in state.get("space", {}) and bool(state["space"][lang.value])
@@ -277,6 +286,7 @@ class StateManager:
raise ValueError(f"No space found for language: {lang}") raise ValueError(f"No space found for language: {lang}")
return state["space"][lang.value] return state["space"][lang.value]
@_auto_save
def add_space( def add_space(
self, lang: Language, file: str, location: str, is_completed: bool self, lang: Language, file: str, location: str, is_completed: bool
) -> None: ) -> None:
@@ -290,12 +300,14 @@ class StateManager:
} }
self._state = state self._state = state
@_auto_save
def remove_space(self, lang: Language) -> None: def remove_space(self, lang: Language) -> None:
state = self._load() state = self._load()
if "space" in state and lang.value in state["space"]: if "space" in state and lang.value in state["space"]:
state["space"][lang.value] = {} state["space"][lang.value] = {}
self._state = state self._state = state
@_auto_save
def clear_space(self, lang: Language) -> None: def clear_space(self, lang: Language) -> None:
state = self._load() state = self._load()
if "space" in state and lang.value in state["space"]: if "space" in state and lang.value in state["space"]:
@@ -305,6 +317,7 @@ class StateManager:
def reload(self) -> None: def reload(self) -> None:
self._state = None self._state = None
@_auto_save
def set_completed(self, lang: Language, is_completed: bool) -> None: def set_completed(self, lang: Language, is_completed: bool) -> None:
state = self._load() state = self._load()
if lang.value not in state.get("space", {}): if lang.value not in state.get("space", {}):
@@ -370,7 +383,7 @@ class StorageManager:
) -> None: ) -> None:
path = STORAGE_DIR / location / lang.value / ("completed" if completed else "") path = STORAGE_DIR / location / lang.value / ("completed" if completed else "")
os.makedirs(path, exist_ok=True) os.makedirs(path, exist_ok=True)
with open(f"{path}/{filename}", "wb") as f: with open(path / f"{filename}.{lang.value}", "wb") as f:
f.write(content) f.write(content)
def read_file(self, location: str, lang: Language, filename: str) -> bytes: def read_file(self, location: str, lang: Language, filename: str) -> bytes:
@@ -379,8 +392,8 @@ class StorageManager:
raise FileNotFoundError( raise FileNotFoundError(
f"File not found in storage: {location}/{filename}.{lang.value}" f"File not found in storage: {location}/{filename}.{lang.value}"
) )
file_path = f"{path}/{filename}" file_path = path / f"{filename}.{lang.value}"
if not os.path.isfile(file_path): if not file_path.is_file():
raise FileNotFoundError(f"File not found in storage: {file_path}") raise FileNotFoundError(f"File not found in storage: {file_path}")
with open(file_path, "rb") as f: with open(file_path, "rb") as f:
return f.read() return f.read()
@@ -391,9 +404,7 @@ class StorageManager:
raise FileNotFoundError( raise FileNotFoundError(
f"File not found in storage: {location}/{filename}.{lang.value}" f"File not found in storage: {location}/{filename}.{lang.value}"
) )
file_path = f"{path}/{filename}" os.remove(path)
if os.path.isfile(file_path):
os.remove(file_path)
def mark_completed(self, location: str, lang: Language, filename: str) -> None: def mark_completed(self, location: str, lang: Language, filename: str) -> None:
uncompleted_file = ( uncompleted_file = (
@@ -541,7 +552,7 @@ def register(location: str):
@click.option( @click.option(
"--force", "-f", is_flag=True, help="Overwrite existing file if it already exists" "--force", "-f", is_flag=True, help="Overwrite existing file if it already exists"
) )
def create(target: str, completed: bool, template: bool, force: bool): def create(target: str, completed: bool, no_template: bool, force: bool):
""" """
지정된 location을 storage에 생성하는 명령어 지정된 location을 storage에 생성하는 명령어
""" """
@@ -563,10 +574,10 @@ def create(target: str, completed: bool, template: bool, force: bool):
if not force: if not force:
return return
if not template: if no_template:
content = b"" content = b""
else: else:
template_path = TEMPLATES_DIR / f"{lang.value}.txt" template_path = TEMPLATES_DIR / f"template.{lang.value}"
if template_path.is_file(): if template_path.is_file():
content = template_path.read_bytes() content = template_path.read_bytes()
click.secho(f"Using template: {template_path}", fg="cyan") click.secho(f"Using template: {template_path}", fg="cyan")
@@ -575,7 +586,7 @@ def create(target: str, completed: bool, template: bool, force: bool):
click.secho(f"Template not found: {template_path}", fg="yellow") click.secho(f"Template not found: {template_path}", fg="yellow")
StorageManager().save_file( StorageManager().save_file(
loc, lang, f"{filename}.{lang.value}", content, completed loc, lang, filename, content, completed
) )
click.secho( click.secho(
f"Created '{filename}.{lang.value}' in location '{loc}'", f"Created '{filename}.{lang.value}' in location '{loc}'",
@@ -633,12 +644,10 @@ def run(lang: str, testcase: tuple[str, ...], verbose: bool):
f_in_path = f"{TC_DIR}/{tc}.in" f_in_path = f"{TC_DIR}/{tc}.in"
f_out_path = f"{TC_DIR}/{tc}.out" f_out_path = f"{TC_DIR}/{tc}.out"
with ( with open(f_out_path, "r", encoding="utf-8") as f_out:
open(f_in_path, "r", encoding="utf-8") as f_in,
open(f_out_path, "r", encoding="utf-8") as f_out,
):
expected = f_out.read().strip() expected = f_out.read().strip()
f_in = open(f_in_path, "r", encoding="utf-8")
proc = subprocess.Popen( proc = subprocess.Popen(
target_language.executable_command, target_language.executable_command,
stdin=f_in, stdin=f_in,
@@ -652,6 +661,7 @@ def run(lang: str, testcase: tuple[str, ...], verbose: bool):
print(line, end="") print(line, end="")
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
f_in.close()
if proc.returncode != 0: if proc.returncode != 0:
click.secho(">>>>>> [RUN TIME ERROR] >>>>>>", fg="red", bold=True) click.secho(">>>>>> [RUN TIME ERROR] >>>>>>", fg="red", bold=True)
@@ -757,10 +767,11 @@ def export(from_: tuple[str, ...], all_: bool, force: bool):
with open(src_path, "rb") as f_src: with open(src_path, "rb") as f_src:
content = f_src.read() content = f_src.read()
os.remove(src_path)
StorageManager().save_file( StorageManager().save_file(
s_loc, from_language, s_file, content, s_is_completed s_loc, from_language, s_file, content, s_is_completed
) )
StateManager().clear_space(from_language)
click.secho( click.secho(
f"Exported '{s_file}.{from_language.value}' to location '{s_loc}'", f"Exported '{s_file}.{from_language.value}' to location '{s_loc}'",
fg="cyan", fg="cyan",
@@ -1062,9 +1073,7 @@ def status():
click.secho(" not completed", fg="cyan", bold=False, nl=False) click.secho(" not completed", fg="cyan", bold=False, nl=False)
click.secho(")", fg="white", bold=False) click.secho(")", fg="white", bold=False)
for lang_name, counts in sorted(langs.items()): for lang_name, counts in sorted(langs.items()):
click.echo( click.echo(f" {lang_name}: {counts['completed']}/{counts['total']}")
f" {lang_name}: {counts['completed']}/{counts['total']}"
)
click.echo() click.echo()
click.secho( click.secho(

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