Submission #59515891


Source Code Expand

/*
 * Author: Number10
 * Created: 2024-11-07 20:11:10
 * Last Modified: 2024-11-07 20:23:18
 */

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int a[N], pre[N], nxt[N];
long long b[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    pre[i] = pre[i - 1] + a[i];
  for (int i = n; i >= 1; --i)
    nxt[i] = nxt[i + 1] + a[i];

  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    b[i] = i;
    sum += i * a[i];
  }

  auto solve = [&]() -> bool {
    if (!sum) return true;
    int sig = sum < 0 ? -1 : 1;
    sum *= sig;
    int p = 0;
    for (int i = 1; i <= n; ++i)
      if (pre[i] == sig * 1) {
        p = i;
        break;
      }
    if (p) {
      for (int i = 1; i <= p; ++i)
        b[i] -= sum;
      return true;
    }
    for (int i = n; i >= 1; --i)
      if (nxt[i] == sig * -1) {
        p = i;
        break;
      }
    if (p) {
      for (int i = p; i <= n; ++i)
        b[i] += sum;
      return true;
    }
    return false;
  };
  if (!solve()) puts("No");
  else {
    puts("Yes");
    for (int i = 1; i <= n; ++i)
      printf("%lld ", b[i]);
  }
  return 0;
}

Submission Info

Submission Time
Task C - ± Increasing Sequence
User Number10
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1267 Byte
Status AC
Exec Time 24 ms
Memory 7768 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:18:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 76
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_1_01.txt, 02_small_1_02.txt, 02_small_1_03.txt, 02_small_1_04.txt, 02_small_1_05.txt, 02_small_1_06.txt, 02_small_1_07.txt, 02_small_1_08.txt, 02_small_1_09.txt, 02_small_1_10.txt, 02_small_1_11.txt, 02_small_1_12.txt, 02_small_1_13.txt, 02_small_1_14.txt, 03_small_2_01.txt, 03_small_2_02.txt, 03_small_2_03.txt, 03_small_2_04.txt, 03_small_2_05.txt, 03_small_2_06.txt, 03_small_2_07.txt, 03_small_2_08.txt, 03_small_2_09.txt, 03_small_2_10.txt, 04_small_zero_01.txt, 04_small_zero_02.txt, 04_small_zero_03.txt, 04_small_zero_04.txt, 05_small_bracket_01.txt, 05_small_bracket_02.txt, 05_small_bracket_03.txt, 05_small_bracket_04.txt, 06_max_rand_01.txt, 06_max_rand_02.txt, 06_max_rand_03.txt, 06_max_rand_04.txt, 06_max_rand_05.txt, 06_max_rand_06.txt, 06_max_rand_07.txt, 06_max_rand_08.txt, 06_max_rand_09.txt, 06_max_rand_10.txt, 07_max_zero_01.txt, 07_max_zero_02.txt, 07_max_zero_03.txt, 07_max_zero_04.txt, 07_max_zero_05.txt, 07_max_zero_06.txt, 07_max_zero_07.txt, 07_max_zero_08.txt, 07_max_zero_09.txt, 07_max_zero_10.txt, 08_max_bracket_01.txt, 08_max_bracket_02.txt, 08_max_bracket_03.txt, 08_max_bracket_04.txt, 08_max_bracket_05.txt, 08_max_bracket_06.txt, 08_max_bracket_07.txt, 08_max_bracket_08.txt, 08_max_bracket_09.txt, 08_max_bracket_10.txt, 09_almost_same_01.txt, 09_almost_same_02.txt, 09_almost_same_03.txt, 09_almost_same_04.txt, 09_almost_same_05.txt, 10_handmade_01.txt, 10_handmade_02.txt, 10_handmade_03.txt, 10_handmade_04.txt, 10_handmade_05.txt, 10_handmade_06.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3860 KiB
01_sample_02.txt AC 1 ms 3804 KiB
01_sample_03.txt AC 1 ms 3672 KiB
02_small_1_01.txt AC 2 ms 3864 KiB
02_small_1_02.txt AC 1 ms 3672 KiB
02_small_1_03.txt AC 1 ms 3744 KiB
02_small_1_04.txt AC 1 ms 3684 KiB
02_small_1_05.txt AC 1 ms 3688 KiB
02_small_1_06.txt AC 1 ms 3592 KiB
02_small_1_07.txt AC 1 ms 3596 KiB
02_small_1_08.txt AC 1 ms 3736 KiB
02_small_1_09.txt AC 1 ms 3576 KiB
02_small_1_10.txt AC 1 ms 3600 KiB
02_small_1_11.txt AC 1 ms 3652 KiB
02_small_1_12.txt AC 1 ms 3652 KiB
02_small_1_13.txt AC 1 ms 3572 KiB
02_small_1_14.txt AC 1 ms 3644 KiB
03_small_2_01.txt AC 1 ms 3656 KiB
03_small_2_02.txt AC 1 ms 3600 KiB
03_small_2_03.txt AC 1 ms 3740 KiB
03_small_2_04.txt AC 1 ms 3652 KiB
03_small_2_05.txt AC 1 ms 3596 KiB
03_small_2_06.txt AC 1 ms 3672 KiB
03_small_2_07.txt AC 1 ms 3668 KiB
03_small_2_08.txt AC 1 ms 3876 KiB
03_small_2_09.txt AC 1 ms 3732 KiB
03_small_2_10.txt AC 1 ms 3684 KiB
04_small_zero_01.txt AC 1 ms 3736 KiB
04_small_zero_02.txt AC 1 ms 3592 KiB
04_small_zero_03.txt AC 1 ms 3684 KiB
04_small_zero_04.txt AC 1 ms 3872 KiB
05_small_bracket_01.txt AC 1 ms 3576 KiB
05_small_bracket_02.txt AC 1 ms 3712 KiB
05_small_bracket_03.txt AC 1 ms 3696 KiB
05_small_bracket_04.txt AC 1 ms 3760 KiB
06_max_rand_01.txt AC 23 ms 7564 KiB
06_max_rand_02.txt AC 23 ms 7468 KiB
06_max_rand_03.txt AC 23 ms 7540 KiB
06_max_rand_04.txt AC 23 ms 7548 KiB
06_max_rand_05.txt AC 22 ms 7468 KiB
06_max_rand_06.txt AC 23 ms 7548 KiB
06_max_rand_07.txt AC 22 ms 7632 KiB
06_max_rand_08.txt AC 23 ms 7612 KiB
06_max_rand_09.txt AC 22 ms 7472 KiB
06_max_rand_10.txt AC 22 ms 7508 KiB
07_max_zero_01.txt AC 23 ms 7764 KiB
07_max_zero_02.txt AC 22 ms 7536 KiB
07_max_zero_03.txt AC 24 ms 7688 KiB
07_max_zero_04.txt AC 23 ms 7684 KiB
07_max_zero_05.txt AC 22 ms 7544 KiB
07_max_zero_06.txt AC 23 ms 7748 KiB
07_max_zero_07.txt AC 22 ms 7768 KiB
07_max_zero_08.txt AC 24 ms 7468 KiB
07_max_zero_09.txt AC 24 ms 7468 KiB
07_max_zero_10.txt AC 23 ms 7488 KiB
08_max_bracket_01.txt AC 12 ms 7572 KiB
08_max_bracket_02.txt AC 12 ms 7584 KiB
08_max_bracket_03.txt AC 12 ms 7400 KiB
08_max_bracket_04.txt AC 12 ms 7472 KiB
08_max_bracket_05.txt AC 12 ms 7536 KiB
08_max_bracket_06.txt AC 12 ms 7572 KiB
08_max_bracket_07.txt AC 12 ms 7460 KiB
08_max_bracket_08.txt AC 12 ms 7508 KiB
08_max_bracket_09.txt AC 12 ms 7764 KiB
08_max_bracket_10.txt AC 12 ms 7528 KiB
09_almost_same_01.txt AC 21 ms 7620 KiB
09_almost_same_02.txt AC 22 ms 7544 KiB
09_almost_same_03.txt AC 22 ms 7628 KiB
09_almost_same_04.txt AC 21 ms 7548 KiB
09_almost_same_05.txt AC 22 ms 7760 KiB
10_handmade_01.txt AC 22 ms 7748 KiB
10_handmade_02.txt AC 22 ms 7620 KiB
10_handmade_03.txt AC 11 ms 7532 KiB
10_handmade_04.txt AC 11 ms 7512 KiB
10_handmade_05.txt AC 11 ms 7548 KiB
10_handmade_06.txt AC 11 ms 7584 KiB