結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-09-03 09:56:44 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                CE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 876 bytes | 
| コンパイル時間 | 453 ms | 
| コンパイル使用メモリ | 51,308 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:10:02 | 
| 合計ジャッジ時間 | 1,191 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:10:1: error: ‘vector’ does not name a type
   10 | vector<int> a;
      | ^~~~~~
main.cpp:11:1: error: ‘vector’ does not name a type
   11 | vector<vector<int>> dp;
      | ^~~~~~
main.cpp: In function ‘int nya(int, int)’:
main.cpp:14:6: error: ‘dp’ was not declared in this scope
   14 |   if(dp[i][j] != -1) { return dp[i][j]; }
      |      ^~
main.cpp:15:23: error: ‘dp’ was not declared in this scope
   15 |   if(i == n) { return dp[i][j] = c==j ? 0 : inf; }
      |                       ^~
main.cpp:17:30: error: ‘a’ was not declared in this scope
   17 |   for(int x=0; p<=c; x++, p+=a[i]) {
      |                              ^
main.cpp:20:10: error: ‘dp’ was not declared in this scope; did you mean ‘p’?
   20 |   return dp[i][j] = res;
      |          ^~
      |          p
main.cpp: In function ‘int main()’:
main.cpp:25:3: error: ‘a’ was not declared in this scope
   25 |   a.assign(n, 0);
      |   ^
main.cpp:27:3: error: ‘dp’ was not declared in this scope
   27 |   dp.assign(n+10, vector<int>(c+10, -1));
      |   ^~
main.cpp:27:19: error: ‘vector’ was not declared in this scope
   27 |   dp.assign(n+10, vector<int>(c+10, -1));
      |                   ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:27:26: error: expected primary-expression before ‘int’
   27 |   dp.assign(n+10, vector<int>(c+10, -1));
      |                          ^~~
main.cpp:24:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |   scanf("%d%d", &c, &n);
      |   ~~~~~^~~~~~~~~~~~~~~~
            
            ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
const int inf = 987654321;
int c, n;
vector<int> a;
vector<vector<int>> dp;
int nya(int i, int j) {
  if(dp[i][j] != -1) { return dp[i][j]; }
  if(i == n) { return dp[i][j] = c==j ? 0 : inf; }
  int res = inf, p = j;
  for(int x=0; p<=c; x++, p+=a[i]) {
    res = min(res, nya(i+1, p) + x);
  }
  return dp[i][j] = res;
}
int main(void) {
  scanf("%d%d", &c, &n);
  a.assign(n, 0);
  for(int i : range(n)) { scanf("%d", &a[i]); }
  dp.assign(n+10, vector<int>(c+10, -1));
  int res = nya(0, 0);
  if(res == inf) { res = -1; }
  printf("%d\n", res);
  return 0;
}