<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>sai-0303-2021のブログ</title>
<link>https://ameblo.jp/sai-0303-2021/</link>
<atom:link href="https://rssblog.ameba.jp/sai-0303-2021/rss20.xml" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
<description>こんにちは！競プロを始めたての学生です！これから主にAtCoderの参加記録と一部解説を載せていきます！</description>
<language>ja</language>
<item>
<title>ABC189</title>
<description>
<![CDATA[ <p>初めまして、SAIと申します！</p><p>&nbsp;</p><p>本日より毎週、Atcoderのコンテストの参加記録をつけていきます！</p><p>まだまだ初心者ですが、少しでも競技プログラミングをやってみようとか思っている人がいれば見てほしいです。</p><p>&nbsp;</p><p>Atcoderとは、日本最大級のプログラミングコンテストサイトです！多数のコンテストがあり、参加することによってレートが変動し、レートによってランクが決まります。このランクが近年では、多数のIT企業で就活に利用できます。<br>一般的には、数学とプログラミングを合わせたものが競技プログラミングといわれます。それほどまでに、論理的思考力が求められる世界ではあるため、論理的思考が苦手な方にはうってつけだと思います。ランクは色で分けられており、次のような順番で存在しています。<br>&nbsp;</p><p style="text-align: center;"><strong>黒色→<span style="color:#bfbfbf;">灰色</span>→<span style="color:#804000;">茶色</span>→<span style="color:#009944;">緑色</span>→<span style="color:#00afff;">水色</span>→<span style="color:#0000ff;">青色</span>→<span style="color:#ffcc00;">黄色</span>→<span style="color:#ff7f00;">橙色</span>→<span style="color:#ff0000;">赤色</span></strong><br>&nbsp;</p><p>問題のランクも上の色で分けられており、例えば茶色レベルの問題であれば、茶diff'(difficultyの略)と表現されます。</p><p>青色以上ははっきり言って次元が違います。<br>私はもうすぐで緑コーダーの茶色コーダーです。(各色にいる人間のことを○色コーダーといいます。)</p><p>自分の復習と記録のために今後もここに記録していきます！少しでも何かお役に立てればうれしいです！</p><p>&nbsp;</p><p>2021/01/23 21:00から開催されたAtcoder Beginnner Contest 189に参加をしてきました！</p><p>&nbsp;</p><div class="ogpCard_root"><article class="ogpCard_wrap" contenteditable="false" style="display:inline-block;max-width:100%"><a class="ogpCard_link" data-ogp-card-log="" href="https://kenkoooo.com/atcoder/#/table/" rel="noopener noreferrer" style="display:flex;justify-content:space-between;overflow:hidden;box-sizing:border-box;width:620px;max-width:100%;height:120px;border:1px solid #e2e2e2;border-radius:4px;background-color:#fff;text-decoration:none" target="_blank"><span class="ogpCard_content" style="display:flex;flex-direction:column;overflow:hidden;width:100%;padding:16px"><span class="ogpCard_title" style="-webkit-box-orient:vertical;display:-webkit-box;-webkit-line-clamp:2;max-height:48px;line-height:1.4;font-size:16px;color:#333;text-align:left;font-weight:bold;overflow:hidden">AtCoder Problems</span><span class="ogpCard_url" style="display:flex;align-items:center;margin-top:auto"><span class="ogpCard_iconWrap" style="position:relative;width:20px;height:20px;flex-shrink:0"><img alt="リンク" class="ogpCard_icon" height="20" loading="lazy" src="https://c.stat100.ameba.jp/ameblo/symbols/v3.20.0/svg/gray/editor_link.svg" style="position:absolute;top:0;bottom:0;right:0;left:0;height:100%;max-height:100%" width="20"></span><span class="ogpCard_urlText" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#757575;font-size:12px;text-align:left">kenkoooo.com</span></span></span></a></article></div><p>&nbsp;</p><p><span style="background-color:#ffcc00;">今回の結果としてはA, B, Dしか解けず😢</span></p><p><span style="background-color:#ffffff;">緑パフォーマンスは出たものの、満足のいく結果ではありませんでした。</span><br>C問題に時間をかけてしまったのが原因でした。</p><p>自分はパイソニスタなのですが、C問題はややオーダーが厳しかったです...</p><p>以下、問題を振り返っていきます！</p><p>&nbsp;</p><ol><li><span style="font-weight:bold;"><span style="font-size:1.4em;"><span style="background-color:#bfbfbf;">Slot</span></span></span><div class="ogpCard_root"><article class="ogpCard_wrap" contenteditable="false" style="display:inline-block;max-width:100%"><a class="ogpCard_link" data-ogp-card-log="" href="https://atcoder.jp/contests/abc189/tasks/abc189_a" rel="noopener noreferrer" style="display:flex;justify-content:space-between;overflow:hidden;box-sizing:border-box;width:620px;max-width:100%;height:120px;border:1px solid #e2e2e2;border-radius:4px;background-color:#fff;text-decoration:none" target="_blank"><span class="ogpCard_content" style="display:flex;flex-direction:column;overflow:hidden;width:100%;padding:16px"><span class="ogpCard_title" style="-webkit-box-orient:vertical;display:-webkit-box;-webkit-line-clamp:2;max-height:48px;line-height:1.4;font-size:16px;color:#333;text-align:left;font-weight:bold;overflow:hidden">A - Slot</span><span class="ogpCard_description" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.6;margin-top:4px;color:#757575;text-align:left;font-size:12px">AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.</span><span class="ogpCard_url" style="display:flex;align-items:center;margin-top:auto"><span class="ogpCard_iconWrap" style="position:relative;width:20px;height:20px;flex-shrink:0"><img alt="リンク" class="ogpCard_icon" height="20" loading="lazy" src="https://c.stat100.ameba.jp/ameblo/symbols/v3.20.0/svg/gray/editor_link.svg" style="position:absolute;top:0;bottom:0;right:0;left:0;height:100%;max-height:100%" width="20"></span><span class="ogpCard_urlText" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#757575;font-size:12px;text-align:left">atcoder.jp</span></span></span><span class="ogpCard_imageWrap" style="position:relative;width:120px;height:120px;flex-shrink:0"><img alt="" class="ogpCard_image" data-ogp-card-image="" height="120" loading="lazy" src="https://img.atcoder.jp/assets/atcoder.png" style="position:absolute;top:50%;left:50%;object-fit:cover;min-height:100%;min-width:100%;transform:translate(-50%,-50%)" width="120"></span></a></article><br>A問題ですので、とても簡単な問題です。標準入力さえ理解していれば、難なく解けるのではないでしょうか。<br>&nbsp;</div><div class="ogpCard_root" style="text-align: center;"><a href="https://stat.ameba.jp/user_images/20210123/23/sai-0303-2021/af/9b/p/o1507020514885902413.png"><img alt="" contenteditable="inherit" height="84" src="https://stat.ameba.jp/user_images/20210123/23/sai-0303-2021/af/9b/p/o1507020514885902413.png" width="620"></a><br>&nbsp;</div></li><li><p><span style="font-size:1.4em;"><span style="font-weight:bold;"><span style="background-color:#bfbfbf;">Alcoholic</span></span></span></p><p>&nbsp;</p><div class="ogpCard_root"><article class="ogpCard_wrap" contenteditable="false" style="display:inline-block;max-width:100%"><a class="ogpCard_link" data-ogp-card-log="" href="https://atcoder.jp/contests/abc189/tasks/abc189_b" rel="noopener noreferrer" style="display:flex;justify-content:space-between;overflow:hidden;box-sizing:border-box;width:620px;max-width:100%;height:120px;border:1px solid #e2e2e2;border-radius:4px;background-color:#fff;text-decoration:none" target="_blank"><span class="ogpCard_content" style="display:flex;flex-direction:column;overflow:hidden;width:100%;padding:16px"><span class="ogpCard_title" style="-webkit-box-orient:vertical;display:-webkit-box;-webkit-line-clamp:2;max-height:48px;line-height:1.4;font-size:16px;color:#333;text-align:left;font-weight:bold;overflow:hidden">B - Alcoholic</span><span class="ogpCard_description" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.6;margin-top:4px;color:#757575;text-align:left;font-size:12px">AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.</span><span class="ogpCard_url" style="display:flex;align-items:center;margin-top:auto"><span class="ogpCard_iconWrap" style="position:relative;width:20px;height:20px;flex-shrink:0"><img alt="リンク" class="ogpCard_icon" height="20" loading="lazy" src="https://c.stat100.ameba.jp/ameblo/symbols/v3.20.0/svg/gray/editor_link.svg" style="position:absolute;top:0;bottom:0;right:0;left:0;height:100%;max-height:100%" width="20"></span><span class="ogpCard_urlText" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#757575;font-size:12px;text-align:left">atcoder.jp</span></span></span><span class="ogpCard_imageWrap" style="position:relative;width:120px;height:120px;flex-shrink:0"><img alt="" class="ogpCard_image" data-ogp-card-image="" height="120" loading="lazy" src="https://img.atcoder.jp/assets/atcoder.png" style="position:absolute;top:50%;left:50%;object-fit:cover;min-height:100%;min-width:100%;transform:translate(-50%,-50%)" width="120"></span></a></article><br>&nbsp;</div><p style="text-align: left;">二回もWAを出してしまった問題。久々のコンテストだったからか浮動小数点演算による誤差を考慮していなかったのが原因です。<br>誤差にさえ気づければあとは簡単。例1を考えてみましょう。<br>n=2, x=15で、アルコール飲料は二つ存在し、一つ目が200mlで5%、二つ目が350mlで3%です。<br>普通に考えれば、アルコールの量を求め、その合計量とxを比較する方法が思いつきます。<br>これを愚直に実装すると、次のようなプログラムとなります。<br><br><a href="https://stat.ameba.jp/user_images/20210123/23/sai-0303-2021/c7/dd/p/o1651037014885903933.png"><img alt="" contenteditable="inherit" height="139" src="https://stat.ameba.jp/user_images/20210123/23/sai-0303-2021/c7/dd/p/o1651037014885903933.png" width="620"></a><br><br>しかしこの方法を用いると、ループ内の除算によって、浮動小数点演算による誤差が生じていしまいます。<br>浮動小数点演算による誤差とは、割り算をした際に言語ごとに表現できる桁数に制限があり、それを超えてしまった際に生じる切り捨て誤差です。競技プログラミングではよくある問題ですので、よければ心にとどめておいていただきたいです。<br>これを回避するために、<span style="background-color:#7cd300;">除算の乗算化</span>を行います。そうすると、プログラムは次のようになります。<br><br><a href="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/01/29/p/o1608036614885907649.png"><img alt="" contenteditable="inherit" height="141" src="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/01/29/p/o1608036614885907649.png" width="620"></a><br><br>ここまでくれば、実装難易度自体はA問題と変わらないと思います！<br>&nbsp;</p></li><li><p style="text-align: left;"><span style="font-weight:bold;"><span style="font-size:1.4em;"><span style="background-color:#fff3c3;">Mandarin Orange</span></span></span></p><div class="ogpCard_root"><article class="ogpCard_wrap" contenteditable="false" style="display:inline-block;max-width:100%"><a class="ogpCard_link" data-ogp-card-log="" href="https://atcoder.jp/contests/abc189/tasks/abc189_c" rel="noopener noreferrer" style="display:flex;justify-content:space-between;overflow:hidden;box-sizing:border-box;width:620px;max-width:100%;height:120px;border:1px solid #e2e2e2;border-radius:4px;background-color:#fff;text-decoration:none" target="_blank"><span class="ogpCard_content" style="display:flex;flex-direction:column;overflow:hidden;width:100%;padding:16px"><span class="ogpCard_title" style="-webkit-box-orient:vertical;display:-webkit-box;-webkit-line-clamp:2;max-height:48px;line-height:1.4;font-size:16px;color:#333;text-align:left;font-weight:bold;overflow:hidden">C - Mandarin Orange</span><span class="ogpCard_description" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.6;margin-top:4px;color:#757575;text-align:left;font-size:12px">AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.</span><span class="ogpCard_url" style="display:flex;align-items:center;margin-top:auto"><span class="ogpCard_iconWrap" style="position:relative;width:20px;height:20px;flex-shrink:0"><img alt="リンク" class="ogpCard_icon" height="20" loading="lazy" src="https://c.stat100.ameba.jp/ameblo/symbols/v3.20.0/svg/gray/editor_link.svg" style="position:absolute;top:0;bottom:0;right:0;left:0;height:100%;max-height:100%" width="20"></span><span class="ogpCard_urlText" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#757575;font-size:12px;text-align:left">atcoder.jp</span></span></span><span class="ogpCard_imageWrap" style="position:relative;width:120px;height:120px;flex-shrink:0"><img alt="" class="ogpCard_image" data-ogp-card-image="" height="120" loading="lazy" src="https://img.atcoder.jp/assets/atcoder.png" style="position:absolute;top:50%;left:50%;object-fit:cover;min-height:100%;min-width:100%;transform:translate(-50%,-50%)" width="120"></span></a></article></div><p>愚直に考えると、l, rを決定するために、次のように二重ループによる解法が思いつきます。<br><br><a href="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/b5/b6/p/o1605039414885915220.png"><img alt="" contenteditable="inherit" height="152" src="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/b5/b6/p/o1605039414885915220.png" width="620"></a><br><br>しかしこのプログラムだと、リスト内参照を含め、オーダーがおよそn^3となり、今回の制限時間である1.5秒に間に合いません。そこで、次のようにプログラムを改変します。<br><br><a href="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/f1/b0/p/o1609028614885919106.png"><img alt="" contenteditable="inherit" height="110" src="https://stat.ameba.jp/user_images/20210124/00/sai-0303-2021/f1/b0/p/o1609028614885919106.png" width="620"></a><br><br>このように、改変することによって、毎回最大値を更新し続けることによって、オーダーをn^2程度に収めることができ、TLEにならずに通すことができます。<br>シンプルなループ回数の削減と時間削減問題でしたが、文章の癖が強く、苦戦した人も多かったのか茶difでした。<br>&nbsp;</p></li><li><p><span style="font-size:1.4em;"><span style="font-weight:bold;"><span style="background-color:#fff3c3;">Logical Expression</span></span></span></p><p>&nbsp;</p><div class="ogpCard_root"><article class="ogpCard_wrap" contenteditable="false" style="display:inline-block;max-width:100%"><a class="ogpCard_link" data-ogp-card-log="" href="https://atcoder.jp/contests/abc189/tasks/abc189_d" rel="noopener noreferrer" style="display:flex;justify-content:space-between;overflow:hidden;box-sizing:border-box;width:620px;max-width:100%;height:120px;border:1px solid #e2e2e2;border-radius:4px;background-color:#fff;text-decoration:none" target="_blank"><span class="ogpCard_content" style="display:flex;flex-direction:column;overflow:hidden;width:100%;padding:16px"><span class="ogpCard_title" style="-webkit-box-orient:vertical;display:-webkit-box;-webkit-line-clamp:2;max-height:48px;line-height:1.4;font-size:16px;color:#333;text-align:left;font-weight:bold;overflow:hidden">D - Logical Expression</span><span class="ogpCard_description" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.6;margin-top:4px;color:#757575;text-align:left;font-size:12px">AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.</span><span class="ogpCard_url" style="display:flex;align-items:center;margin-top:auto"><span class="ogpCard_iconWrap" style="position:relative;width:20px;height:20px;flex-shrink:0"><img alt="リンク" class="ogpCard_icon" height="20" loading="lazy" src="https://c.stat100.ameba.jp/ameblo/symbols/v3.20.0/svg/gray/editor_link.svg" style="position:absolute;top:0;bottom:0;right:0;left:0;height:100%;max-height:100%" width="20"></span><span class="ogpCard_urlText" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#757575;font-size:12px;text-align:left">atcoder.jp</span></span></span><span class="ogpCard_imageWrap" style="position:relative;width:120px;height:120px;flex-shrink:0"><img alt="" class="ogpCard_image" data-ogp-card-image="" height="120" loading="lazy" src="https://img.atcoder.jp/assets/atcoder.png" style="position:absolute;top:50%;left:50%;object-fit:cover;min-height:100%;min-width:100%;transform:translate(-50%,-50%)" width="120"></span></a></article></div><p>この問題は、問題を以下に解釈し直すかが問題となってきます。まず考えるのがANDの場合の処理についてです。この場合、ともにTrueでなければなりません。逆にORであればともにFalseである場合を除いて、求める出力が可能となります。<br>したがって、次のようなプログラムが考えられます。<br><br><a href="https://stat.ameba.jp/user_images/20210124/01/sai-0303-2021/44/48/p/o1611021014885925946.png"><img alt="" height="81" src="https://stat.ameba.jp/user_images/20210124/01/sai-0303-2021/44/48/p/o1611021014885925946.png" width="620"></a><br><br>このプログラムでは、まず最大でも2^(n+1)通りしか存在しないことを理解しなければなりません。すべてがORであった場合、すべての値がFalseである場合以外が条件を満たすため、そのような考えに至ります。<br>そして次に、本プログラムではANDの場合の処理についてのみを考慮しています。なぜならORの場合は、すべてがFalseになる場合のみが条件を満たさないからです。ANDの場合は、ANDが出てきたのが何回目かに着目し、その回数を2の指数とした分だけ減らします。これは、解説のように漸化式的に表現をすることによって解釈をすることも可能ですが、私は次のように解釈をしました。<br>ANDが出てきた瞬間に先にも述べましたが、ともにTrueでなければ条件を満たしません。それゆえに、可能性はその時点で半分に減少し、さらにそれ以前の事象も考慮すると、2^(ANDが出てきた回数番号)分だけ減少すると解釈できるのです。<br>これによって、無事ACを勝ち取ることができます。<br>&nbsp;</p></li></ol><div><span style="font-size:1.4em;"><span style="font-weight:bold;"><span style="background-color:#bfebff;">まとめ</span></span></span><br>もう少しやれたかなというのが、正直な感想です。最近別のことで忙しく、あまり練習が出来ていないのが原因なのかも...精進しなければと痛感しました。無事レートは上がったので、今回は良しとしておきます。<br>&nbsp;</div><div>また、プログラミングと聞くと、長いコードを書くというイメージがありがちですが、競技プログラミングは一概にそうとは言えません！D問題であったとしても、論理的思考力と考察次第でいくらでもコードを短くしていけるのが競技プログラミングのいいところです！<br>&nbsp;</div><div>Atcoderは、プログラミングを少しかじったことがある程度の人でも十二分に楽しめるサイトとなっております。数学的・論理的思考力を高めることができ、今では多くの企業で就活の際の指標にも利用されています。ぜひ、機会があれば私と一緒に競プロライフを楽しみましょう！<br>&nbsp;</div><div class="ogpCard_root">&nbsp;</div><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/sai-0303-2021/entry-12652171416.html</link>
<pubDate>Sun, 24 Jan 2021 01:56:03 +0900</pubDate>
</item>
</channel>
</rss>
