about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-02-15 21:05:21 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-02-16 14:57:43 +0700
commit2b91f9554b326aea138bd8a0acbfaa10d9ad59aa (patch)
tree10053cf99e42711999d33b422a8735c5367d339f
parent0cf49da1527983b9d165cd394b82c6bcbcafca60 (diff)
downloadcp-2b91f9554b326aea138bd8a0acbfaa10d9ad59aa.tar.gz
[codechef] Try CP again after almost a year
-rwxr-xr-xcodechef/frogs.py10
-rw-r--r--codechef/frogs.scm17
-rwxr-xr-xcodechef/maxfun.py5
-rwxr-xr-xcodechef/maxfun.raku6
-rw-r--r--codechef/maxfun.rs13
-rw-r--r--codechef/teamname.rs26
6 files changed, 77 insertions, 0 deletions
diff --git a/codechef/frogs.py b/codechef/frogs.py
new file mode 100755
index 0000000..23f51e5
--- /dev/null
+++ b/codechef/frogs.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+for t in range(int(input())):
+    n = int(input())
+    w, l = list(map(int, input().split())), list(map(int, input().split()))
+    last, result, frogs = -1, 0, sorted(zip(w, range(n), l))
+    for weight, position, length in frogs:
+        hits = 0 if position > last else (last-position)//length + 1
+        last = position + hits*length
+        result += hits
+    print(result)
diff --git a/codechef/frogs.scm b/codechef/frogs.scm
new file mode 100644
index 0000000..ab65f30
--- /dev/null
+++ b/codechef/frogs.scm
@@ -0,0 +1,17 @@
+(define (read-line n) (if (> n 0) (cons (read) (read-line (1- n))) '()))
+(let test ((t (read)))
+  (when (> t 0)
+    (display
+      (let* ((n (read)) (w (read-line n)) (l (read-line n))
+             (i (let range ((k 1) (m n))
+                  (if (> m 0) (cons k (range (1+ k) (1- m))) '()))))
+        (let loop ((last 0)
+                   (frogs (map cdr (sort (map list w i l)
+                                         (lambda (u v) (< (car u) (car v)))))))
+          (if (null? frogs)
+            0
+            (let* ((first (car frogs)) (pos (car first)) (len (cadr first))
+                   (hits (if (> pos last) 0 (1+ (quotient (- last pos) len)))))
+              (+ hits (loop (+ pos (* hits len)) (cdr frogs))))))))
+    (newline)
+    (test (1- t))))
diff --git a/codechef/maxfun.py b/codechef/maxfun.py
new file mode 100755
index 0000000..fa0f64f
--- /dev/null
+++ b/codechef/maxfun.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+for i in range(int(input())):
+    input()
+    a = list(map(int, input().split()))
+    print(max(a)-min(a)<<1)
diff --git a/codechef/maxfun.raku b/codechef/maxfun.raku
new file mode 100755
index 0000000..bddd6ca
--- /dev/null
+++ b/codechef/maxfun.raku
@@ -0,0 +1,6 @@
+#!/usr/bin/env raku
+for ^get() {
+    get;
+    my @a = map (words get): +*;
+    put (@a.max - @a.min) * 2
+}
diff --git a/codechef/maxfun.rs b/codechef/maxfun.rs
new file mode 100644
index 0000000..444284b
--- /dev/null
+++ b/codechef/maxfun.rs
@@ -0,0 +1,13 @@
+use std::io::BufRead;
+
+fn main() {
+    let stdin = std::io::stdin();
+    let mut lines = stdin.lock().lines();
+    for _t in 0..lines.next().unwrap().unwrap().trim().parse::<u8>().unwrap() {
+        let _n = lines.next().unwrap().unwrap();
+        let line = lines.next().unwrap().unwrap();
+        let i = line.split(' ').map(|x| x.trim().parse().unwrap());
+        let a: Vec<i64> = i.collect();
+        println!("{}", (a.iter().max().unwrap() - a.iter().min().unwrap()) * 2);
+    }
+}
diff --git a/codechef/teamname.rs b/codechef/teamname.rs
new file mode 100644
index 0000000..23f23e3
--- /dev/null
+++ b/codechef/teamname.rs
@@ -0,0 +1,26 @@
+use std::collections::HashSet;
+use std::io::BufRead;
+
+fn main() {
+    let stdin = std::io::stdin();
+    let mut lines = stdin.lock().lines();
+    for _t in 0..lines.next().unwrap().unwrap().trim().parse::<u8>().unwrap() {
+        let _n = lines.next().unwrap();
+        let line = lines.next().unwrap().unwrap();
+        let words: Vec<&str> = line.split(' ').collect();
+
+        let mut graph: [HashSet<String>; 26] = Default::default();
+        for word in &words {
+            let i = word.chars().next().unwrap() as usize;
+            graph[i - 97].insert(word[1..].to_string());
+        }
+
+        println!("{}", (0..26).fold(0, |r, i| r + (0..26).fold(0, |s, j| {
+            if i == j { s } else {
+                let intersect = graph[i].iter()
+                    .fold(0, |c, d| c + graph[j].contains(d) as usize);
+                s + (graph[i].len() - intersect) * (graph[j].len() - intersect)
+            }
+        })))
+    }
+}