結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
![]() |
提出日時 | 2018-09-15 06:41:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 118 ms / 1,500 ms |
コード長 | 1,300 bytes |
コンパイル時間 | 1,146 ms |
コンパイル使用メモリ | 84,376 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-07-07 23:42:27 |
合計ジャッジ時間 | 5,721 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%d%d", &t, &n); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:49:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | for (int i = 0; i < n; i++) scanf("%d", &ts[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 733.cc: No.733 分身並列コーディング - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 17; const int NBITS = 1 << MAX_N; const int INF = 0x7f7f7f7f; /* typedef */ /* global variables */ int ts[MAX_N]; int dp[NBITS][MAX_N + 1]; /* subroutines */ inline void setmin(int &a, int b) { if (a > b) a = b; } /* main */ int main() { int t, n; scanf("%d%d", &t, &n); for (int i = 0; i < n; i++) scanf("%d", &ts[i]); int nbits = 1 << n; memset(dp, 0x7f, sizeof(dp)); memset(dp[0], 0, sizeof(dp[0])); for (int bits = 0; bits < nbits; bits++) for (int i = 0; i <= n; i++) if (dp[bits][i] < INF) { if (i < n && dp[bits][i] <= t) dp[bits][i + 1] = 0; for (int j = 0, bj = 1; j < n; j++, bj <<= 1) if (! (bits & bj)) setmin(dp[bits | bj][i], dp[bits][i] + ts[j]); } int mini = 0; for (; mini <= n; mini++) if (dp[nbits - 1][mini] == 0) break; printf("%d\n", mini); return 0; }