網頁

Sunday 11 July 2010

IOI 2004 Artemis

O(N2) 時間可過! 但 memory 就唔得
做法也是用 inclusive-exclusive, 問題係點樣唔用 O(N2) memory 去 implement

先把點 sort by x
之後由左至右咁做, fix i for j, 每次都係 compute s[xj][yj]+s[xi][yi]-s[xi][yj]-s[xj][yi] 之類,
發現除了 s[xj][yj] 和 s[xi][yi], 其實都只係 depend on xi, yi

所以只要把和 i 有關的 2N 個「關鍵點」(共N2個「關鍵點」)計出, 即 s[xi][*], s[*][yi], 便可把 memory 降至 linear

No comments:

Post a Comment