[topic] 情報オリンピック2007年度国内本選問題5

中高生向けの情報オリンピック国内本選2007年度問題5です。

問題文(下記PDFの11ページ目)
http://www.ioi-jp.org/joi/2007/2008-ho-prob_and_sol/2008-ho.pdf
コンテスト概要
http://www.ioi-jp.org/joi/2007/2008-ho-prob_and_sol/index.html
サンプルデータ(出題時に公開)
http://www.ioi-jp.org/joi/2007/2008-ho-prob_and_sol/joi2008.zip
採点データ(出題時に非公開)
http://www.ioi-jp.org/joi/2007/2008-ho-prob_and_sol/data.zip

「問題ごとに、プログラムの実行時間(や使用メモリ量)に制限が設定されています。」にご注意ください。本問では、制限時間1秒、メモリ制限64MBとなっています。

出題時はサンプルデータのみが公開され、採点は、採点データによる、自動採点にて行われます。

実際のコンテストでは、予選通過者48名が対象となっていて、100点満点中38点以上とった、16名が本選通過です。

Posted feedbacks - diff

memsetを使うようにしたところ,大幅に高速化しました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--- 5.cpp    Wed Jun 25 16:56:20 2008
+++ 5.cpp    Sat Jun 28 20:33:02 2008
@@ -5,6 +5,7 @@
 #include <queue>
 #include <utility>
 #include <cassert>
+#include <cstring> // memset()
 
 #define REP(i, b, e) for (size_t i = b; i < e; ++i)
 
@@ -24,7 +25,7 @@
 template <typename T>
 size_t find(const std::vector<T>& v, const T& value)
 {
-    std::vector<T>::const_iterator it = std::lower_bound(v.begin(), v.end(), value);
+    typename std::vector<T>::const_iterator it = std::lower_bound(v.begin(), v.end(), value);
 
     assert(it != v.end());
 
@@ -78,7 +79,7 @@
     const size_t xn = xs.size() - 1;
     const size_t yn = ys.size() - 1;
 
-    std::vector<std::vector<int> > map(xn, std::vector<int>(yn, true));
+    std::vector<std::vector<unsigned char> > map(xn, std::vector<unsigned char>(yn, 1));
 
     for (std::vector<rect>::const_iterator it = tapes.begin(); it != tapes.end(); ++it)
     {
@@ -87,9 +88,9 @@
         const size_t lower_yi = find(ys, it->bottom);
         const size_t upper_yi = find(ys, it->top);
 
-        REP(xi, lower_xi, upper_xi) REP(yi, lower_yi, upper_yi)
+        REP(xi, lower_xi, upper_xi)
         {
-            map[xi][yi] = false;
+            std::memset(&map[xi][lower_yi], 0, (upper_yi - lower_yi) * sizeof(unsigned char));
         }
     }

Index

Feed

Other

Link

Pathtraq

loading...