結果
| 問題 |
No.1199 お菓子配り-2
|
| コンテスト | |
| ユーザー |
57tggx
|
| 提出日時 | 2020-08-23 11:29:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 994 bytes |
| コンパイル時間 | 450 ms |
| コンパイル使用メモリ | 56,828 KB |
| 最終ジャッジ日時 | 2025-01-13 12:25:17 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:31:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%lld", &tmp);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
// このコードは, WA になります.
// このコードの出力を見ると,それぞれのテストケースについてどのようなお菓子の食べ方が最適だったのか,そして食べられたお菓子は全部で何個だったのかが分かります.
#include <cstdio>
#include <cmath>
#include <algorithm>
int n, m;
long long a[1123];
long long dp[1123][2];
int count(int i, int j){
if(i == 0) return 0;
if(dp[i][j] == dp[i - 1][j]){
return count(i - 1, j);
}else if(std::abs(dp[i][j] - dp[i - 1][!j]) == a[i - 1]){
int tmp = count(i - 1, !j);
printf("%d ", i);
return ++tmp;
}else{
fputs("error", stderr);
exit(-1);
}
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
long long tmp;
scanf("%lld", &tmp);
a[i] += tmp;
}
dp[i + 1][0] = std::max(dp[i][0], dp[i][1] - a[i]);
dp[i + 1][1] = std::max(dp[i][1], dp[i][0] + a[i]);
}
printf("\ncount: %d / %d\n", count(n, 1), n);
}
57tggx