Successfully reported this slideshow.
Your SlideShare is downloading. ×

AtCoder Regular Contest 028 解説

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 20 Ad

More Related Content

Slideshows for you (20)

Similar to AtCoder Regular Contest 028 解説 (20)

Advertisement

More from AtCoder Inc. (20)

AtCoder Regular Contest 028 解説

  1. 1. Aၥ㢟 ᑠ▼䜢ྲྀ䜛䝀䞊䝮
  2. 2. ၥ㢟ᴫせ • ⿄䛻Nಶ䛾ᑠ▼䛜ධ䛳䛶䛔䜛䚹 • Ant䛥䜣䚸Bug䛟䜣䚸Ant䛥䜣...䛾㡰䛻஺஫䛻ྲྀ䛳䛶䛔䛟䚹 • Ant䛥䜣䛿Aಶ䛪䛴䚸Bug䛥䜣䛿Bಶ䛪䛴ᑠ▼䜢ྲྀ䜛䚹 • 䛹䛱䜙䛾䝍䞊䞁䛾ᚋ䛻⿄䛜✵䛻䛺䜛䛛䜢ồ䜑䜘䚹 • ไ⣙ • 1 ≤ N, A, B ≤ 1000
  3. 3. ゎἲ • 䝅䝭䝳䝺䞊䝅䝵䞁䛧䜎䛧䜗䛖䚹 • 䜹䜴䞁䝍䛾ኚᩘ䜢⏝ព䛧䚸䛭䛣䛛䜙A䛸B䜢஺஫䛻ᘬ 䛔䛶䛔䛟䚹 • 䜹䜴䞁䝍䛜0௨ୗ䛻䛺䛳䛯䛸䛝䛻䛹䛱䜙䛾䝍䞊䞁䛰䛳 䛯䛛䜢ฟຊ䛩䜛䚹
  4. 4. Bၥ㢟 ≉ู㈹
  5. 5. ၥ㢟ᴫせ • 䝁䞁䝔䝇䝖䛜⾜䜟䜜䚸Nே䛾ே䛜ཧຍ䛧䛯䚹 • i఩䛾ே䛜඲ཧຍ⪅䛾䛖䛱ఱ␒┠䛻ⱝ䛔䛛䛜ධຊ䛥 䜜䜛䚹 • 1఩ࠥj఩䛾ே䛾䛖䛱K␒┠䛻ⱝ䛔ே䛾㡰఩䜢䚸K~N 䛾j䛻ᑐ䛧䛶ฟຊ䛫䜘䚹 • ไ⣙ • 1 ≤ N ≤ 10^5
  6. 6. 40Ⅼゎἲ (N≤1000) • 䛭䜜䛮䜜䛾⟅䛘䜢ẖᅇồ䜑䜛䚹 • 1఩䛛䜙j఩䜎䛷䛾ே䛾ⱝ䛥䜢䝋䞊䝖䛧䛶䚸K␒┠䛾せ ⣲䜢ぢ䜛䚹
  7. 7. ‶Ⅼゎἲ • j䜢ᑠ䛥䛔᪉䛛䜙㡰␒䛻ቑ䜔䛧䛶䛔䛝䚸⟅䛘䜢᭦᪂䛧 䛶䛔䛟䚹 • 䛒䜛᫬Ⅼ䛷K+1␒┠௨㝆䛻䛺䛳䛯ே䛿䚸䛭䜜௨㝆K ␒┠䛻䛺䜛஦䛿䛺䛔䚹 • 䠍ே㏣ຍ䛩䜛ᗘ䛻䚸 – K+1␒┠௨㝆䛰䛳䛯䜙䛺䛻䜒䛧䛺䛔䚹 – K␒┠௨ෆ䛰䛳䛯䜙ೃ⿵䛻ຍ䛘䚸ೃ⿵䛾୰䛛䜙୍␒⪁䛡 䛶䛔䜛ே䜢ೃ⿵䛛䜙๐㝖䛩䜛䚹 • 䛷䚸ೃ⿵䛾䛖䛱᭱䜒⪁䛡䛶䛔䜛ே䛾㡰఩䜢ฟຊ䛩䜛䚹
  8. 8. ‶Ⅼゎἲ • 䛭䜜䜢ᐇ⌧䛩䜛䛯䜑䛻䛿䝕䞊䝍ᵓ㐀䛜ᚲせ䚹ᚲせ 䛺᧯స䛿䚸 – せ⣲䜢㏣ຍ䛩䜛 – せ⣲䛾䛖䛱᭱䜒኱䛝䛔್䜢ྲྀ䜚ฟ䛩 • priority queue䠄ඃඛ㡰఩䛴䛝queue䠅 • ྛ᧯స䜢O(log せ⣲ᩘ)䛷⾜䛖䛣䛸䛜ฟ᮶䜎䛩䚹 • ゝㄒ䛻䜘䛳䛶ᶆ‽䝷䜲䝤䝷䝸䛜䛒䛳䛯䜚䛩䜛䛾䛷ㄪ 䜉䛶䜏䜎䛧䜗䛖䚹
  9. 9. Cၥ㢟 㧗ᶫ⋤ᅜ䛾ศ๭⤫἞
  10. 10. ၥ㢟ᴫせ • 㡬ⅬᩘN䛾ᮌ䛜୚䛘䜙䜜䜛䚹 • 㡬Ⅼv䛜ྲྀ䜚㝖䛛䜜䛯᫬䛻䛷䛝䜛㐃⤖ᡂศ䛾䛖䛱䚸 ᭱䜒኱䛝䛔䜒䛾䜢䚸ྛv䛻䛴䛔䛶ồ䜑䜘䚹 • ไ⣙ • 1 ≤ N ≤ 10^5
  11. 11. 30Ⅼゎἲ (N≤1000) • 䛭䜜䛮䜜䛾⟅䛘䜢ẖᅇồ䜑䜛䚹 • ᮌ䛾ၥ㢟䛻䛺䜜䛶䛔䜜䜀⡆༢䚹 • DFS䛺䛹䜢䛩䜜䜀䜘䛔䚹
  12. 12. ‶Ⅼゎἲ • 䛸䜚䛒䛘䛪᰿௜䛝ᮌ䛸䛧䛶⪃䛘䜛䚹 • DFS䛧䛺䛜䜙ᮌDP䜢䛩䜜䜀䚸Ꮚ᪉ྥ䛾㒊ศᮌ䛾䝃䜲 䝈䜢ồ䜑䜛䛣䛸䛜ฟ᮶䜛䚹 • 䛧䛛䛧䚸ぶ᪉ྥ䛾㒊ศᮌ䛾䝃䜲䝈䛿䛹䛖䛧䛯䜒䛾䛰 䜝䛖䛛䚹 • →N-­‐1-­‐(Ꮚ᪉ྥ䛾㒊ศᮌ䛾䝃䜲䝈䛾࿴) 䛷ồ䜑䜙䜜䜛䟿
  13. 13. 䛚䜎䛡 • ヲ⣽䛻䛴䛔䛶䛿┬䛝䜎䛩䛜䚸 • 㒊ศᮌ䛾䝃䜲䝈䛾᭱኱್䜢ồ䜑䜛ၥ㢟䛿䚸ᮌ䛾ศ ๭⤫἞䜢⾜䛖᫬䛻౑䛳䛯䜚䛧䜎䛩䚹
  14. 14. Dၥ㢟 ὀᩥ䛾ከ䛔㧗ᶫၟᗑ
  15. 15. ၥ㢟ᴫせ • N✀㢮䛾ၟရ䛜䛭䜜䛮䜜A[i]ಶ䛒䜛䚹 • 䛂k✀㢮┠䛾ၟရ䜢xಶ㑅䜆䛸䛝䚸ྜィMಶ䛾ၟရ䜢 㑅䜆᪉ἲ䛿ఱ㏻䜚䛒䜛䛛䛃䛸䛔䛖䜽䜶䝸䛻Qᅇ⟅䛘䜘䚹 • ไ⣙ • 1 ≤ N ≤ 2000 • 1 ≤ M ≤ 2000 • 1 ≤ Q ≤ 500000
  16. 16. 10Ⅼゎἲ (N,M,Q≤100) • ྛ䜽䜶䝸䛭䜜䛮䜜䛷DP䜢䛩䜛䚹 • DP[i][j]=i✀㢮┠䜎䛷䛷jಶ㑅䜆᪉ἲ䛾ಶᩘ • ₞໬ᘧ䛿 • DP[i][j] = ΣDP[i-­‐1][j-­‐a[i]]~DP[i-­‐1][j] • ⣼✚࿴䜢ྲྀ䛳䛶䛚䛡䜀O(1)䛷᭦᪂䛷䛝䜛䚹
  17. 17. 30Ⅼゎἲ (N,M≤100) • ၟရ䛾㡰␒䜢ධ䜜᭰䛘䛶䜒⟅䛘䛿ኚ䜟䜙䛺䛔 • ၟရi௨እ䛰䛡䜢౑䛳䛯䛸䛝䛾DP䝔䞊䝤䝹䛸䛔䛖䛾䜢 䛒䜙䛛䛨䜑඲䛶䛾i䛻䛴䛔䛶ồ䜑䛶䛚䛟䚹 • ๓ฎ⌮䠖O(N^2M) • ྛ䜽䜶䝸䠖O(M) • 䛸䛺䜚䚸30Ⅼ䜢ᚓ䜛䛣䛸䛜ฟ᮶䜛䚹
  18. 18. 80Ⅼゎἲ(N,M≤2000,Q≤1000) • ྛi䛤䛸䛻᭱ึ䛛䜙DP䜢䜔䜚┤䛧䛶䛔䜛䛾䛜↓㥏䛳䜍 䛔 • 0~j䜎䛷䜢౑䛳䛯䛸䛝䛾DP䝔䞊䝤䝹䛸 • j~N䜎䛷䜢౑䛳䛯䛸䛝䛾DP䝔䞊䝤䝹 • 䜢ᣢ䛳䛶䛚䛟䚹(せ䛩䜛䛻ᕥഃ䛸ྑഃ䛾DP䝔䞊䝤䝹) • ྛ䜽䜶䝸䛻䛴䛝䚸䠎䛴䛾DP䝔䞊䝤䝹䜢ཧ↷䛩䜛䛣䛸䛷䚸 O(M)䛷⟅䛘䜢ồ䜑䜛䛣䛸䛜ฟ᮶䜛䚹
  19. 19. ‶Ⅼゎἲ • ྛ䜽䜶䝸䛻O(1)䛷⟅䛘䛺䛡䜜䜀䛺䜙䛺䛔䚹 • ၟရi௨እ䛰䛡䜢౑䛳䛯䛸䛝䛾DP䝔䞊䝤䝹䛸䛔䛖䛾䜢 䛒䜙䛛䛨䜑඲䛶䛾i䛻䛴䛔䛶ồ䜑䛶䛚䛝䛯䛔䚹 • ⪃ᐹ • ၟရ䛾㡰␒䛿㛵ಀ䛜䛺䛔 • DP䛾₞໬ᘧ䛿DP[i-­‐1]䛻䛚䛡䜛(㒊ศ)࿴䛾ᙧᘧ
  20. 20. ᡠ䛩DP • DP[i]䛛䜙DP[i-­‐1]䜢᚟ඖ䛩䜛䚹 • DP[i][j] = ΣDP[i-­‐1][j-­‐a[i]]~DP[i-­‐1][j] • → • DP[i-­‐1][j] = DP[i][j]-­‐ΣDP[i-­‐1][j-­‐a[i]]~DP[i-­‐1][j-­‐1] • O(M)䛷᚟ඖ䛷䛝䜛䟿 • ၟရ䛾㡰␒䛿ኚ䛘䛶䜒⟅䛘䛿ኚ䜟䜙䛺䛔䛾䛷䚸 DP[N]䛛䜙䚸䛂ၟရi௨እ䛰䛡䜢౑䛳䛯䛸䛝䛾DP䝔䞊䝤 䝹䛃䛜ྛi䛻䛴䛔䛶᚟ඖ䛷䛝䜎䛩䚹

×