結果

問題 No.1433 Two color sequence
ユーザー Santosh BethaSantosh Betha
提出日時 2021-03-19 22:30:00
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,020 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-29 17:36:14
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'f':
main.c:60:10: warning: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
   60 |   return abs(r - b);
      |          ^~~
main.c:10:1: note: include '<stdlib.h>' or provide a declaration of 'abs'
    9 | #include <limits.h>
  +++ |+#include <stdlib.h>
   10 | struct color

ソースコード

diff #

/*
 ___   _   _    ___  __   ___ _  _     __   ____ ___ _  _   _
|__   /_\  |\ |  |  |  | |__  |__|     |_|  |__   |  |__|  /_\
___| /   \ | \|  |  |__| ___| |  |     |__| |___  |  |  | /   \

*/
#include <stdio.h>
#include <math.h>
#include <limits.h>
struct color
{
  char x;
  int y;
};
int f(struct color *, int, int);
int main()
{
  int n;
  scanf("%d", &n);
  struct color a[n];
  char s[n];
  scanf("%s", s);
  int i;
  for (i = 0; i < n; i++)
  {
    int v;
    scanf("%d", &v);
    a[i].x = s[i];
    a[i].y = v;
  }
  int j, max = INT_MIN;
  for (i = 0; i < n; i++)
  {
    for (j = i + 1; j < n; j++)
    {
      int ans = f(a, i, j);
      if (max < ans)
      {
        max = ans;
      }
    }
  }
  printf("%d", max);
  return 0;
}
int f(struct color *a, int l, int h)
{
  int i, r = 0, b = 0;
  for (i = l; i <= h; i++)
  {
    if (a[i].x == 'R')
    {
      r += a[i].y;
    }
    else
    {
      b += a[i].y;
    }
  }
  return abs(r - b);
}
0