結果
| 問題 |
No.2840 RGB Plates
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-25 09:17:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 628 bytes |
| コンパイル時間 | 2,218 ms |
| コンパイル使用メモリ | 194,864 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-25 09:17:48 |
| 合計ジャッジ時間 | 4,039 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=1e5+10;
int dp[MAX],a[3010];
int main()
{
int n,i,j,K,ans,sum;
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(n<=20) K=5000*n;
else if(n<=200) K=5000*10;
else K=5000*2;
for(i=1;i<=K;i++) dp[i]=0;
dp[0]=1;
for(i=1;i<=n;i++)
{
for(j=K;j>=a[i];j--)
{
dp[j]+=dp[j-a[i]];
dp[j]=min(dp[j],2);
}
}
ans=-1;
for(i=1;i<=min(K+1,sum/2)-1;i++)
{
if(dp[i]>=2)
{
ans=sum-2*i;
break;
}
}
printf("%d\n",ans);
return 0;
}