Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
Download leetcode/lc1439/code.rs from Gax-c/VeriContest_Lite: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1439/code.rs
- Command line
-
hf download hf://datasets/Gax-c/VeriContest_Lite/leetcode/lc1439/code.rs
-
curl -L -o code.rs https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1439/code.rs
1.52 kB
| fn merge_capped_exec(a: &Vec<i32>, b: &Vec<i32>, cap: usize) -> Vec<i32> { | |
| let mut result: Vec<i32> = Vec::new(); | |
| let mut i: usize = 0; | |
| let mut j: usize = 0; | |
| while result.len() < cap && (i < a.len() || j < b.len()) { | |
| if j >= b.len() || (i < a.len() && a[i] <= b[j]) { | |
| result.push(a[i]); | |
| i += 1; | |
| } else { | |
| result.push(b[j]); | |
| j += 1; | |
| } | |
| } | |
| result | |
| } | |
| fn shift_exec(s: &Vec<i32>, shift: i32) -> Vec<i32> { | |
| let mut result: Vec<i32> = Vec::new(); | |
| let mut idx: usize = 0; | |
| while idx < s.len() { | |
| result.push(s[idx] + shift); | |
| idx += 1; | |
| } | |
| result | |
| } | |
| fn fold_cols_exec(mat: &Vec<Vec<i32>>, row: usize, tail: &Vec<i32>, cap: usize) -> Vec<i32> { | |
| let n = mat[row].len(); | |
| let mut acc: Vec<i32> = Vec::new(); | |
| let mut c: usize = n; | |
| while c > 0 { | |
| c -= 1; | |
| let shifted = shift_exec(tail, mat[row][c]); | |
| acc = merge_capped_exec(&shifted, &acc, cap); | |
| } | |
| acc | |
| } | |
| fn capped_sums_exec(mat: &Vec<Vec<i32>>, cap: usize) -> Vec<i32> { | |
| let mut tail: Vec<i32> = Vec::new(); | |
| if cap >= 1 { | |
| tail.push(0); | |
| } | |
| let m = mat.len(); | |
| let mut row: usize = m; | |
| while row > 0 { | |
| row -= 1; | |
| tail = fold_cols_exec(mat, row, &tail, cap); | |
| } | |
| tail | |
| } | |
| impl Solution { | |
| pub fn kth_smallest(mat: Vec<Vec<i32>>, k: i32) -> i32 { | |
| let l = capped_sums_exec(&mat, k as usize); | |
| let ans = l[(k - 1) as usize]; | |
| ans | |
| } | |
| } | |