結果
問題 |
No.1433 Two color sequence
|
ユーザー |
|
提出日時 | 2021-03-19 22:30:00 |
言語 | C (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,020 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 31,872 KB |
実行使用メモリ | 17,096 KB |
最終ジャッジ日時 | 2024-11-18 23:19:29 |
合計ジャッジ時間 | 55,871 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 2 TLE * 18 |
コンパイルメッセージ
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
ソースコード
/* ___ _ _ ___ __ ___ _ _ __ ____ ___ _ _ _ |__ /_\ |\ | | | | |__ |__| |_| |__ | |__| /_\ ___| / \ | \| | |__| ___| | | |__| |___ | | | / \ */ #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); }