답안 #15424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15424 2015-07-12T07:27:48 Z xhae 달리는 게임 (kriii3_E) C++14
70 / 70
157 ms 9536 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
  int n;
  scanf("%d", &n);

  vector<int> val(n);
  for (int i=0; i<n; i++)
    scanf("%d", &val[i]);

  vector<int> mark(n);
  long long sum = 0;
  for (int i=n-1; i>=0; i--) {
    sum = max(sum + val[i], 0LL + val[i]);
    if (sum >= 0) mark[i] = 1;
  }

  long long res = 0;
  long long mult = 0;
  for (int i=0; i<n; i++) {
    if (mark[i]) {
      mult ++;
      res += mult * val[i];
    } else mult = 0;
  }
  printf("%lld\n", res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1720 KB Output is correct
2 Correct 0 ms 1720 KB Output is correct
3 Correct 0 ms 1720 KB Output is correct
4 Correct 0 ms 1720 KB Output is correct
5 Correct 0 ms 1720 KB Output is correct
6 Correct 0 ms 1720 KB Output is correct
7 Correct 0 ms 1720 KB Output is correct
8 Correct 0 ms 1720 KB Output is correct
9 Correct 0 ms 1720 KB Output is correct
10 Correct 0 ms 1720 KB Output is correct
11 Correct 0 ms 1720 KB Output is correct
12 Correct 0 ms 1720 KB Output is correct
13 Correct 0 ms 1720 KB Output is correct
14 Correct 0 ms 1720 KB Output is correct
15 Correct 0 ms 1720 KB Output is correct
16 Correct 0 ms 1720 KB Output is correct
17 Correct 0 ms 1720 KB Output is correct
18 Correct 0 ms 1720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2112 KB Output is correct
2 Correct 0 ms 2112 KB Output is correct
3 Correct 8 ms 2112 KB Output is correct
4 Correct 12 ms 2504 KB Output is correct
5 Correct 0 ms 2504 KB Output is correct
6 Correct 11 ms 2504 KB Output is correct
7 Correct 95 ms 5632 KB Output is correct
8 Correct 143 ms 9536 KB Output is correct
9 Correct 157 ms 9536 KB Output is correct