結果
問題 | No.332 数列をプレゼントに |
ユーザー |
![]() |
提出日時 | 2015-12-25 02:19:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 1,381 bytes |
コンパイル時間 | 1,340 ms |
コンパイル使用メモリ | 162,088 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-12-24 07:29:45 |
合計ジャッジ時間 | 3,441 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:42:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | LL X;scanf("%d %lld",&n,&X); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:45:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | int w;scanf("%d",&w); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long LL;int dp[1000001];int unko[1000001];int v[100];pair<int,LL> pv[100];inline void init(){fill(dp,dp+1000001,-1);dp[0]=0;}int ans[100];int n;bool dfs(int id,int p,int sz,LL now,LL X){if(now>X)return false;if(X-now<=1000000&&dp[X-now]>=0){LL k=(X-now);while(k){ans[p++]=dp[k]-1;k=unko[k];}sort(ans,ans+p);for(int i = 0,s=0; i < n; i++){if(s<p&&ans[s]==i){putchar('o');s++;}else putchar('x');}putchar('\n');return true;}if(id<sz){ans[p]=pv[id].first;if(dfs(id+1,p+1,sz,now+pv[id].second,X))return true;if(dfs(id+1,p,sz,now,X))return true;}return false;}int main() {init();LL X;scanf("%d %lld",&n,&X);int sz=0,top=0;for(int i = 0; i < n; i++){int w;scanf("%d",&w);if(w<=10000){top=top+w;for(int j = top; j >= w; j--)if(dp[j]<0&&dp[j-w]>=0){dp[j]=i+1;unko[j]=j-w;}}else{pv[sz].first=i;pv[sz].second=w;sz++;}}if(dfs(0,0,sz,0,X)==false)printf("No\n");return 0;}