<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>難易度-1300 - IQパズルステップ</title>
	<atom:link href="https://chokomon.com/tag/difficulty-1300/feed/" rel="self" type="application/rss+xml" />
	<link>https://chokomon.com</link>
	<description>ちょこっと頭を良くするIQパズル問題集</description>
	<lastBuildDate>Tue, 11 Oct 2022 09:34:00 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://chokomon.com/wp-content/uploads/2022/02/cropped-icon512-32x32.png</url>
	<title>難易度-1300 - IQパズルステップ</title>
	<link>https://chokomon.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【paizaの森練習問題コンテスト6】球数制限 (paizaランク D)-解答例-PHP編</title>
		<link>https://chokomon.com/42-forest_contest-06-01-00666/</link>
					<comments>https://chokomon.com/42-forest_contest-06-01-00666/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Tue, 11 Oct 2022 09:33:59 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[練習問題コンテスト]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクD]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6992</guid>

					<description><![CDATA[【paizaの森練習問題コンテスト6】過去問題6 > 球数制限 (paizaランク D 相当) [難易度: 1306 ±53] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/paiza_set/42-forest_contest/">paizaの森練習問題コンテスト6</a>】<a href="https://paiza.jp/works/mondai/forest_contest_006/forest_contest_006__d_balllimit" target="_blank" rel="noreferrer noopener">過去問題6 > 球数制限 (paizaランク D 相当)</a> [難易度: <strong>1306 ±53</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img fetchpriority="high" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/10/42-06-01-01.png" alt="" class="wp-image-6993"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>プロ野球歴 3 年目 20 歳の佐々尾くんは投手として前途有望なため、ある一定の球数に到達すると怪我を考慮して、たとえパーフェクトピッチングを継続していたとしても降板させられます。佐々尾くんは現在<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-light-orange-color">n</mark></code>イニング投げており、i (1 ≦ i ≦ n) イニング目に投げた球数は m_i 球です。n イニング投げ終わったときに<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-light-orange-color">k</mark></code>球以上投げているとそれ以降のイニングは投げられません。佐々尾くんは次のイニングで続投できるかどうかを答えてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>5 100<br>12<br>14<br>20<br>8<br>17</p>



<p><strong>出力値（例）</strong><br>Yes</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    
    $total = 0;
    
    for($i=0; $i&lt;$n; $i++) {
        $m = trim(fgets(STDIN));
        $total += $m;
    }
    echo ($total &lt; $k) ? "Yes" : "No";
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/10/42-06-01-02.png" alt="" class="wp-image-6994"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/42-forest_contest-06-01-00666/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】【区間の長さ】 区間の長さ 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-09-04-00654/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-09-04-00654/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 18 Sep 2022 06:21:56 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6911</guid>

					<description><![CDATA[【累積和メニュー】> FINAL問題【区間の長さ】 区間の長さ 4 (paizaランク C 相当) [難易度: 1331 ±49] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_length_boss" target="_blank" rel="noreferrer noopener">FINAL問題【区間の長さ】 区間の長さ 4 (paizaランク C 相当)</a> [難易度: <strong>1331 ±49</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-04-01.png" alt="" class="wp-image-6912"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, K が与えられます。</p>



<p>N 個の整数 a_1, a_2, ..., a_N からなる数列 a が与えられます。</p>



<p>この数列において、総和が K 以下の区間のうち、最大の長さを求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>10 15<br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>3</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $maxLength = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $maxLength = max($maxLength, $r-$i-1);
    }
    echo $maxLength;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-04-02.png" alt="" class="wp-image-6913"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-09-04-00654/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】2 次元上のいもす法 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-07-04-00644/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-07-04-00644/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Thu, 15 Sep 2022 07:20:26 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6855</guid>

					<description><![CDATA[【累積和メニュー】&#62; 【2 次元上のいもす法】STEP: 4 2 次元上のいもす法 4 (paizaランク C 相当)&#160;[難易度:&#160;1378&#160;±52] ※リンク先へ移動するためには[paiza]へのログイ…]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】&gt; <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__2d_imos_step4" target="_blank" rel="noreferrer noopener">【2 次元上のいもす法】STEP: 4 2 次元上のいもす法 4 (paizaランク C 相当)</a>&nbsp;[難易度:&nbsp;<strong>1378&nbsp;±52</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-04-01.png" alt="" class="wp-image-6856"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N が与えられます。</p>



<p>2 行目に a_i, b_i, c_i, d_i (1 ≦ i ≦ N) が N 行で与えられます。</p>



<p>5 行 5 列のマスがあり、最初、マスには全て 0 が書かれています。</p>



<p>N 個の長方形領域の左上の座標 (a_i, b_i) と右下の座標 (c_i, d_i) が与えられます。それぞれの範囲に対して、その範囲に含まれるマスに 1 を加算していきます。</p>



<p>5 行 5 列のマスに書かれた値のうち、最大の値をいもす法を用いて求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>5<br>1 1 3 3<br>2 2 4 4<br>3 3 5 5<br>1 3 3 5<br>3 1 5 3</p>



<p><strong>出力値（例）</strong><br>5</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $n = trim(fgets(STDIN));
    
    $sRow = array_fill(0, 6, 0);
    $s = array_fill(0, 6, $sRow);
    
    for ($i=0; $i&lt;$n; $i++) {
        list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
        $x1[] = $a;
        $y1[] = $b;
        $x2[] = $c;
        $y2[] = $d;
        
        $s[$y1[$i]-1][$x1[$i]-1]++;
        $s[$y2[$i]][$x2[$i]]++;
        $s[$y1[$i]-1][$x2[$i]]--;
        $s[$y2[$i]][$x1[$i]-1]--;
    }
    
    // 横方向への累積和
    for ($i=0; $i&lt;6; $i++) {
        for ($j=1; $j&lt;6; $j++) {
            $s[$i][$j] += $s[$i][$j-1];
        }
    }
    
    // 縦方向の累積和
    for ($i=1; $i&lt;6; $i++) {
        for ($j=0; $j&lt;6; $j++) {
            $s[$i][$j] += $s[$i-1][$j];
        }
    }
    //print_r($s);
    
    // 最大値を調べる
    $tile_max = 0;
    for ($i=0; $i&lt;6; $i++) {
        for ($j=0; $j&lt;6; $j++) {
            if ($tile_max &lt; $s[$i][$j]) {
                $tile_max = $s[$i][$j];
            }
        }
    }
    echo $tile_max;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-04-02.png" alt="" class="wp-image-6857"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-07-04-00644/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】【1 次元上のいもす法】1 次元上のいもす法 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-06-04-00640/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-06-04-00640/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Tue, 13 Sep 2022 06:46:42 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6833</guid>

					<description><![CDATA[【累積和メニュー】> FINAL問題【1 次元上のいもす法】1 次元上のいもす法 4 (paizaランク C 相当) [難易度: 1315 ±48] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__1d_imos_boss" target="_blank" rel="noreferrer noopener">FINAL問題【1 次元上のいもす法】1 次元上のいもす法 4 (paizaランク C 相当)</a> [難易度: <strong>1315 ±48</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-06-04-01.png" alt="" class="wp-image-6834"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, Q が与えられます。</p>



<p>2 行目に Q 個の範囲 [L_i, R_i] (1 ≦ i ≦ Q) が整数で Q 行で与えられます。</p>



<p>横に並んだ N 個のマスがあり、最初、マスには全て 0 が書かれています。</p>



<p>それぞれの範囲に対して、その範囲に含まれるマスに 1 を加算していきます。</p>



<p>すべての加算が終わった時点での N 個のマスに書かれた値のうち、最大の値をいもす法を用いて求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>10 5<br>1 3<br>1 8<br>3 8<br>3 6<br>7 9</p>



<p><strong>出力値（例）</strong><br>4</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $q) = explode(" ", trim(fgets(STDIN)));

    $a = array_fill(0, $n+1, 0);
    
    for ($i=0; $i&lt;$q; $i++) {
        list($left, $right) = explode(" ", trim(fgets(STDIN)));
        $l[] = $left;
        $r[] = $right;
        
        $a[$l[$i]-1]++;
        $a[$r[$i]]--;
    }
    
    for ($i=0; $i&lt;$n+1; $i++) {
        if ($i &gt; 0) $a[$i] += $a[$i-1];
    }
    //print_r($a);
    
    echo max($a);
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-06-04-02.png" alt="" class="wp-image-6835"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-06-04-00640/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】二次元累積和 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-05-04-00633/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-05-04-00633/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Mon, 12 Sep 2022 01:10:58 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6788</guid>

					<description><![CDATA[【累積和メニュー】&#62; 【二次元累積和】STEP: 4 二次元累積和 4 (paizaランク C 相当)&#160;[難易度:&#160;1377&#160;±46] ※リンク先へ移動するためには[paiza]へのログインが必要です。 …]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】&gt; <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__2dsection_sum_step4" target="_blank" rel="noreferrer noopener">【二次元累積和】STEP: 4 二次元累積和 4 (paizaランク C 相当)</a>&nbsp;[難易度:&nbsp;<strong>1377&nbsp;±46</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-05-04-01.png" alt="" class="wp-image-6790"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 a, b, c, d が与えられます。</p>



<p>2 行目以降に 5 行 5 列の整数の二次元配列 A が与えられます。</p>



<p>A の i 行目 j 列目を A_{i, j} (0 ≦ i ≦ 4, 0 ≦ j ≦ 4) と表すことにします。</p>



<p>長方形領域の左上の要素を A_{a, b} 、右下の要素を A_{c, d} としたとき、この長方形領域内の整数の和を累積和を用いて求め、一行で出力してください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>1 1 3 3<br>1 2 3 4 5<br>2 3 4 5 6<br>3 4 5 6 7<br>4 5 6 7 8<br>5 6 7 8 9</p>



<p><strong>出力値（例）</strong><br>45</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($ax, $by, $cx, $dy) = explode(" ", trim(fgets(STDIN)));
    
    for ($i=0; $i&lt;5; $i++) {
        $a[$i] = explode(" ", trim(fgets(STDIN)));
    }
    //print_r($a);
        
    $sy = $ax; $sx = $by; $ly = $cx; $lx = $dy;
    $h = 5; $w = 5;
    
    $sRow = array_fill(0, $w+1, 0);
    $s = array_fill(0, $h+1, $sRow);
    
    for ($i=0; $i&lt;$h; $i++) {
        for ($j=0; $j&lt;$w; $j++) {
            $s[$i+1][$j+1] = $a[$i][$j]+$s[$i][$j+1]+$s[$i+1][$j]-$s[$i][$j];
        }
    }
    //print_r($s);
    
    $ans = $s[$ly+1][$lx+1]-$s[$sy][$lx+1]-$s[$ly+1][$sx]+$s[$sy][$sx];
    echo $ans;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-05-04-02.png" alt="" class="wp-image-6791"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-05-04-00633/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】二次元累積和 2 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-05-02-00631/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-05-02-00631/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 11 Sep 2022 20:28:53 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6778</guid>

					<description><![CDATA[【累積和メニュー】&#62; 【二次元累積和】STEP: 2 二次元累積和 2 (paizaランク C 相当)&#160;[難易度:&#160;1342&#160;±44] ※リンク先へ移動するためには[paiza]へのログインが必要です。 …]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】&gt; <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__2dsection_sum_step2" target="_blank" rel="noreferrer noopener">【二次元累積和】STEP: 2 二次元累積和 2 (paizaランク C 相当)</a>&nbsp;[難易度:&nbsp;<strong>1342&nbsp;±44</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-05-02-01.png" alt="" class="wp-image-6779"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>5 行 5 列の整数の二次元配列 A が与えられます。</p>



<p>A の i 行目 j 列目を A_{i, j} (0 ≦ i ≦ 4, 0 ≦ j ≦ 4) と表すことにします。</p>



<p>長方形領域の左上の要素を A_{1, 1}, 右下の要素を A_{3, 3} としたとき、この長方形領域内の整数の和を累積和を用いて求め、一行で出力してください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>1 2 3 4 5<br>2 3 4 5 6<br>3 4 5 6 7<br>4 5 6 7 8<br>5 6 7 8 9</p>



<p><strong>出力値（例）</strong><br>45</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    for ($i=0; $i&lt;5; $i++) {
        $a[$i] = explode(" ", trim(fgets(STDIN)));
    }
    //print_r($a);
        
    $sy = 1; $sx = 1; $ly = 3; $lx = 3;
    $h = 5; $w = 5;
    
    $sRow = array_fill(0, $w+1, 0);
    $s = array_fill(0, $h+1, $sRow);
    
    for ($i=0; $i&lt;$h; $i++) {
        for ($j=0; $j&lt;$w; $j++) {
            $s[$i+1][$j+1] = $a[$i][$j]+$s[$i][$j+1]+$s[$i+1][$j]-$s[$i][$j];
        }
    }
    //print_r($s);
    
    $ans = $s[$ly+1][$lx+1]-$s[$sy][$lx+1]-$s[$ly+1][$sx]+$s[$sy][$sx];
    echo $ans;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-05-02-02.png" alt="" class="wp-image-6780"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-05-02-00631/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間内の個数 (文字列) 2 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-04-02-00627/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-04-02-00627/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sat, 10 Sep 2022 18:28:31 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6751</guid>

					<description><![CDATA[【累積和メニュー】> 【区間内の個数 (文字列)】STEP: 2 区間内の個数 (文字列) 2 (paizaランク C 相当) [難易度: 1341 ±35] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__string_count_step2" target="_blank" rel="noreferrer noopener">【区間内の個数 (文字列)】STEP: 2 区間内の個数 (文字列) 2 (paizaランク C 相当)</a> [難易度: <strong>1341 ±35</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-04-02-01.png" alt="" class="wp-image-6752"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-light-orange-color">'b'</mark></code> と <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-light-orange-color">'w'</mark></code> で構成された文字列 str が与えられます。</p>



<p>文字列 str の 3 文字目から 8 文字目までの <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-light-orange-color">'b'</mark></code> の個数を累積和を用いて求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>bwwbwbbwbw</p>



<p><strong>出力値（例）</strong><br>3</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $str = trim(fgets(STDIN));
    
    //$len = mb_strlen($str);
    
    for ($i=0; $i&lt;10; $i++) {
        ($str[$i] == "b") ? $b[] = 1 : $b[] = 0;
    }
    $s[0] = 0;
    for ($i=0; $i&lt;10; $i++) {
        $s[$i+1] = $s[$i]+$b[$i];
    }
    //print_r($s);
    echo $s[8]-$s[2];
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-04-02-02.png" alt="" class="wp-image-6753"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-04-02-00627/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】【連続する N 個の和の最大値】 連続する N 個の和の最大値 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-02-04-00619/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-02-04-00619/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Wed, 07 Sep 2022 19:57:26 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6699</guid>

					<description><![CDATA[【累積和メニュー】&#62; FINAL問題【連続する N 個の和の最大値】 連続する N 個の和の最大値 4 (paizaランク C 相当)&#160;[難易度:&#160;1377&#160;±29] ※リンク先へ移動するためには[pai…]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】&gt; <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__sum_max_boss" target="_blank" rel="noreferrer noopener">FINAL問題【連続する N 個の和の最大値】 連続する N 個の和の最大値 4 (paizaランク C 相当)</a>&nbsp;[難易度:&nbsp;<strong>1377&nbsp;±29</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-02-04-01.png" alt="" class="wp-image-6700"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, K が与えられます。</p>



<p>2 行目に N 個の整数 a_0, a_1, a_2, ..., a_(N-1) が与えられます。</p>



<p>連続する K 個の整数の和の最大値を、累積和を使うことで求め、一行で出力してください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>10 3<br>1 2 3 4 5 6 7 8 9 10</p>



<p><strong>出力値（例）</strong><br>27</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $sum[0] = 0;
 
    for ($i=0; $i&lt;$n; $i++) {
        $sum[$i+1] = $sum[$i]+$a[$i];
    }
    //print_r($sum);

    $max_sum = 0;
    for ($i=0; $i&lt;$n-$k+1; $i++) {
        $max_sum = max($max_sum, $sum[$i+$k]-$sum[$i]);
    }
    
    echo $max_sum;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-02-04-02.png" alt="" class="wp-image-6701"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-02-04-00619/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【ユークリッドの互除法メニュー】ユークリッドの互除法 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/24-euclidean_primer-01-01-00585/</link>
					<comments>https://chokomon.com/24-euclidean_primer-01-01-00585/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 19 Aug 2022 19:07:12 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[ユークリッドの互除法メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6481</guid>

					<description><![CDATA[【ユークリッドの互除法メニュー】> 【拡張ユークリッドの互除法】STEP: 1 ユークリッドの互除法 (paizaランク C 相当) [難易度: 1383 ±27] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/24-euclidean_primer/">ユークリッドの互除法メニュー</a>】> <a href="https://paiza.jp/works/mondai/euclidean_primer/euclidean_primer__simple_gcd" target="_blank" rel="noreferrer noopener">【拡張ユークリッドの互除法】STEP: 1 ユークリッドの互除法 (paizaランク C 相当)</a> [難易度: <strong>1383 ±27</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/08/24-01-01-01.png" alt="" class="wp-image-6482"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>2 つの整数 A , B の最大公約数（以後 gcd(A , B)）を高速に求めるアルゴリズムとして、ユークリッドの互除法があります。<br>gcd(A, B) をユークリッドの互除法で求める手順は次の通りです。<br></p>



<p class="has-gray-background-color has-background">1. A , B のうち、いずれかが 0 の場合 手順 3 に進む<br>2. A , B のうち小さい方で大きい方をわり、大きい方をその余りで置き換え、手順 1 に戻る<br>3. このとき、0 でない方の数が求めたい最大公約数になっている。</p>



<p>例として A = 15 , B = 40 にユークリッドの互除法を用いて最大公約数を求めると、次の通りになります。<br>（[]内の数字は手順の番号を表す）</p>



[2] A = 15 , B = 40<br>[3] A &lt; B なので B / A = 2 余り 10 より B = 10<br>[2] A = 15 , B = 10<br>[3] B &lt; A なので A / B = 1 余り 5 より A = 5<br>[2] A = 5 , B = 10<br>[3] A &lt; B なので B / A = 2 余り 0 より B = 0<br>[2] A = 5 , B = 0<br>[4] よって、15 と 40 の最大公約数は 5 となる。</p>



<p>2 つの整数 A , B が与えられるので、ユークリッドの互除法を用いて A , B の最大公約数を求めましょう。</p>



<p></p>



<p><strong>入力値（例）</strong><br>45 15</p>



<p><strong>出力値（例）</strong><br>15</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    
    // 自然数 a &gt; b を確認・入替
    if ($a &lt; $b) {
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
    
    // ユークリッドの互除法
    $r = $a % $b;
    while ($r != 0) {
        $a = $b;
        $b = $r;
        $r = $a % $b;
    }
    echo $b. "\n";
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/08/24-01-01-02.png" alt="" class="wp-image-6483"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/24-euclidean_primer-01-01-00585/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【DPメニュー】2項間漸化式 1 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/18-dp_primer-01-01-00554/</link>
					<comments>https://chokomon.com/18-dp_primer-01-01-00554/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 12 Aug 2022 13:01:21 +0000</pubDate>
				<category><![CDATA[DPメニュー]]></category>
		<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6239</guid>

					<description><![CDATA[【DPメニュー】> 【漸化式】STEP: 1 2項間漸化式 1 (paizaランク C 相当) [難易度: 1390 ±13] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/18-dp_primer/">DPメニュー</a>】> <a href="https://paiza.jp/works/mondai/dp_primer/dp_primer_recursive_formula_step0" target="_blank" rel="noreferrer noopener">【漸化式】STEP: 1 2項間漸化式 1 (paizaランク C 相当)</a> [難易度: <strong>1390 ±13</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/08/18-01-01-01.png" alt="" class="wp-image-6240"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>整数 x, d, k が与えられます。<br>次のように定められた数列の k 項目の値を出力してください。</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">・ a_1 = x 
・ a_n = a_{n-1} + d (n ≧ 2)</pre></div>



<h3 class="wp-block-heading">(ヒント)</h3>



<p>等差数列の公式を使えばDPを使わずとも答えを求めることができますが、練習だと思ってDPで解いてみましょう。</p>



<p>DPを考える際には、まず漸化式を考えるとよいです。漸化式は、数列の各項をその前の項を用いて記述した式です。問題で与えられている&nbsp;<code>a_n = a_{n-1} + d</code>&nbsp;という式がこの問題における漸化式となっています。</p>



<p>では、実際にこの問題を解いてみましょう。最終的に求めたいのは a_k です。a_1 ~ a_{k-1} がわかっているとして、a_k がどうなるかを考えてみましょう (a_1 ~ a_{k-1} が、「はじめに」の部分で述べた"部分問題"に相当しています) 。a_{k-1} がわかっているので、<code>a_k = a_{k-1} + d</code>&nbsp;とすればよいですね。今回は a_1 が x であることがわかっているので、順に a_2, a_3, a_4, ... を計算していけば a_k が求まることがわかるかと思います。</p>



<p>以下の疑似コードを参考にして、あなたの得意な言語で実装してみましょう。</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">a[1] &lt;- x 

for i = 2 to k 
a[i] &lt;- a[i-1] + d 

print a[k]</pre></div>



<p></p>



<p><strong>入力値（例）</strong><br>0 7 9</p>



<p><strong>出力値（例）</strong><br>56</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($x, $d, $k) = explode(" ", trim(fgets(STDIN)));
    
    $a[1] = $x;
    
    for ($i = 2; $i &lt;= $k; $i++) {
        $a[$i] = $a[$i - 1] + $d;
    }
    
    echo $a[$k];
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/08/18-01-01-02.png" alt="" class="wp-image-6241"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/18-dp_primer-01-01-00554/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
