about summary refs log tree commit diff
path: root/codechef
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-10-14 20:59:08 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-10-14 20:59:08 +0700
commitcacc165173d67fa110766a555afe3020967d220c (patch)
treea859612503a5c4f4d870c074cc19d07b1eb3aed2 /codechef
parent4b8df7227736b7c41af56e053d40decc309fe7f9 (diff)
downloadcp-cacc165173d67fa110766a555afe3020967d220c.tar.gz
Practice some C++
Diffstat (limited to 'codechef')
-rw-r--r--codechef/marm.cc58
-rwxr-xr-xcodechef/msng.py25
-rw-r--r--codechef/msv.cc39
-rw-r--r--codechef/s10e.cc35
-rw-r--r--codechef/saktan.cc32
5 files changed, 189 insertions, 0 deletions
diff --git a/codechef/marm.cc b/codechef/marm.cc
new file mode 100644
index 0000000..3866330
--- /dev/null
+++ b/codechef/marm.cc
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+int
+main()
+{
+  int t, n;
+  long k;
+
+  cin >> t;
+  while (t--)
+    {
+      cin >> n >> k;
+      long d = k / n, m = k % n;
+      vector<long> a (n);
+      for (int i = 0; i < n; ++i)
+        cin >> a[i];
+
+      for (int i = 0; i < n / 2; ++i)
+        {
+          switch ((d + (m > i)) % 3)
+            {
+            case 1:
+              cout << (a[i] ^ a[n - i - 1]);
+              break;
+            case 2:
+              cout << a[n - i - 1];
+              break;
+            default:
+              cout << a[i];
+            }
+          cout << ' ';
+        }
+
+      if (n % 2)
+        cout << ((d + (m > n >> 1)) ? 0 : a[n >> 1]) << ' ';
+
+      for (int i = n - (n >> 1); i < n; ++i)
+        {
+          switch ((d + (m > i)) % 3)
+            {
+            case 1:
+              cout << a[n - i - 1];
+              break;
+            case 2:
+              cout << (a[i] ^ a[n - i - 1]);
+              break;
+            default:
+              cout << a[i];
+            }
+          cout << ((i + 1 == n) ? '\n' : ' ');
+        }
+    }
+
+  return 0;
+}
diff --git a/codechef/msng.py b/codechef/msng.py
new file mode 100755
index 0000000..bf8b262
--- /dev/null
+++ b/codechef/msng.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+from collections import Counter
+
+for t in range(int(input())):
+    n, x = int(input()), []
+    for i in range(n):
+        b, y = input().split()
+        if b == '-1':
+            guesses = set()
+            for b in range(2, 37):
+                try:
+                    guess = int(y, b)
+                except ValueError:
+                    pass
+                else:
+                    if guess > 10 ** 12: break
+                    guesses.add(guess)
+            x.extend(guesses)
+        else:
+            guess = int(y, int(b))
+            if guess <= 10 ** 12: x.append(guess)
+    try:
+        print(min(k for k, v in Counter(x).items() if v == n))
+    except ValueError:
+        print(-1)
diff --git a/codechef/msv.cc b/codechef/msv.cc
new file mode 100644
index 0000000..6206cff
--- /dev/null
+++ b/codechef/msv.cc
@@ -0,0 +1,39 @@
+#include <algorithm>
+#include <iostream>
+#include <unordered_map>
+
+using namespace std;
+
+int
+main()
+{
+  int t, n, i;
+  long a;
+
+  cin >> t;
+  while (t--)
+    {
+      int star = 0;
+      unordered_map<long, int> m;
+
+      cin >> n;
+      while (n--)
+        {
+          cin >> a;
+          star = max (m[a], star);
+
+          for (i = 1; i * i < a; ++i)
+            if (a % i == 0)
+              {
+                m[i]++;
+                m[a / i]++;
+              }
+          if (i * i == a)
+            m[i]++;
+        }
+
+      cout << star << endl;
+    }
+
+  return 0;
+}
diff --git a/codechef/s10e.cc b/codechef/s10e.cc
new file mode 100644
index 0000000..5e5c0b7
--- /dev/null
+++ b/codechef/s10e.cc
@@ -0,0 +1,35 @@
+#include <algorithm>
+#include <deque>
+#include <iostream>
+
+using namespace std;
+
+int
+main()
+{
+  int t;
+  int tmp;
+  deque<int> p;
+
+  cin >> t;
+  while (t--)
+    {
+      int n;
+      int r = 0;
+
+      cin >> n;
+      p.clear();
+      while (n--)
+        {
+          cin >> tmp;
+          auto it = min_element (p.begin(), p.end());
+          r += it == p.end() || *it > tmp;
+          p.push_back (tmp);
+          if (p.size() > 5)
+            p.pop_front();
+        }
+      cout << r << endl;
+    }
+
+  return 0;
+}
diff --git a/codechef/saktan.cc b/codechef/saktan.cc
new file mode 100644
index 0000000..96ef43a
--- /dev/null
+++ b/codechef/saktan.cc
@@ -0,0 +1,32 @@
+#include <iostream>
+#include <numeric>
+#include <vector>
+
+using namespace std;
+
+int
+main()
+{
+  int t;
+  long n, m, q, x, y;
+
+  cin >> t;
+  while (t--)
+    {
+      cin >> n >> m >> q;
+      vector<int> u (n), v (m);
+
+      while (q--)
+        {
+          cin >> x >> y;
+          u[x - 1] ^= 1;
+          v[y - 1] ^= 1;
+        }
+
+      x = accumulate (u.begin(), u.end(), 0);
+      y = accumulate (v.begin(), v.end(), 0);
+      cout << x * (m - y) + (n - x) * y << endl;
+    }
+
+  return 0;
+}