about summary refs log tree commit diff
path: root/usth/MATH2.3/5/turing.cc
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-01-14 18:29:11 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-01-14 18:29:11 +0700
commita3dd2581ed4847670f81157091016c14ca18803d (patch)
tree3362ab15de119f1e75799f58715b7683e6bfd6ca /usth/MATH2.3/5/turing.cc
parent65b8ebda4c47fa27ac28899fb2b29097f445b6df (diff)
downloadcp-a3dd2581ed4847670f81157091016c14ca18803d.tar.gz
[usth/MATH2.3] Mathemate Discretely
Diffstat (limited to 'usth/MATH2.3/5/turing.cc')
-rw-r--r--usth/MATH2.3/5/turing.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/usth/MATH2.3/5/turing.cc b/usth/MATH2.3/5/turing.cc
new file mode 100644
index 0000000..7ef5deb
--- /dev/null
+++ b/usth/MATH2.3/5/turing.cc
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <deque>
+#include <tuple>
+#include <unordered_map>
+
+using namespace std;
+
+int
+main ()
+{
+  int n;
+  unordered_map<int, unordered_map<int, tuple<int, int, int>>> tuples;
+  cin >> n;
+  while (n--)
+    {
+      int s, x, t, y, d;
+      cin >> s >> x >> t >> y >> d;
+      tuples[s][x] = {t, y, d};
+    }
+
+  deque<int> input;
+  cin >> n;
+  while (n--)
+    {
+      int i;
+      cin >> i;
+      input.push_back (i);
+    }
+
+  int o {0}, i {0}, s {0}, x, d;
+  for (;;)
+    {
+      tie (s, x, d) = tuples[s][input[i - o]];
+      if (!d)
+        break;
+
+      if (i < o)
+        {
+          input.push_front (x);
+          o++;
+        }
+      else if (i - o == input.size ())
+        input.push_back (x);
+      else
+        input[i - o] = x;
+
+      if (d < 0)
+        i--;
+      else
+        i++;
+    }
+
+  for (auto const& i : input)
+    cout << i;
+  cout << endl;
+}