Submission #10217864
Source Code Expand
import copy n = int(input()) a = list(map(int, input().split())) # print(a) def f(org_a, odd): a = copy.copy(org_a) ans = 0 if a[0] == 0: a[0] = 1 if odd else -1 ans += 1 elif a[0] > 0 and not odd: ans += a[0] + 1 a[0] = -1 elif a[0] < 0 and odd: ans += -a[0] + 1 a[0] = 1 current_sum = a[0] for i in range(1, len(a)): move = 0 is_positive = current_sum > 0 current_sum += a[i] if is_positive and current_sum >= 0: move = -current_sum - 1 elif not is_positive and current_sum <= 0: move = -current_sum + 1 current_sum += move # print(current_sum) a[i] += move ans += abs(move) return ans # print(a) print(min(f(a, True), f(a, False)))
Submission Info
Submission Time | |
---|---|
Task | C - Sequence |
User | saitoxu |
Language | Python (3.4.3) |
Score | 300 |
Code Size | 851 Byte |
Status | AC |
Exec Time | 134 ms |
Memory | 15156 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00-00.txt, 00-01.txt, 00-02.txt |
All | 00-00.txt, 00-01.txt, 00-02.txt, 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00-00.txt | AC | 22 ms | 3444 KB |
00-01.txt | AC | 22 ms | 3444 KB |
00-02.txt | AC | 22 ms | 3444 KB |
01-00.txt | AC | 133 ms | 14596 KB |
01-01.txt | AC | 133 ms | 14844 KB |
01-02.txt | AC | 130 ms | 15156 KB |
01-03.txt | AC | 125 ms | 13844 KB |
01-04.txt | AC | 121 ms | 13524 KB |
01-05.txt | AC | 114 ms | 12268 KB |
01-06.txt | AC | 130 ms | 14432 KB |
01-07.txt | AC | 119 ms | 13440 KB |
01-08.txt | AC | 134 ms | 14596 KB |
01-09.txt | AC | 120 ms | 13520 KB |
01-10.txt | AC | 103 ms | 11836 KB |
01-11.txt | AC | 131 ms | 14300 KB |
01-12.txt | AC | 133 ms | 14596 KB |
01-13.txt | AC | 121 ms | 13268 KB |
01-14.txt | AC | 133 ms | 14596 KB |