結果

問題 No.247 線形計画問題もどき
ユーザー Kmcode1
提出日時 2015-07-17 22:56:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,792 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 202,944 KB
実行使用メモリ 12,956 KB
最終ジャッジ日時 2024-07-08 09:22:07
合計ジャッジ時間 10,040 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d", &c);
      |         ~~~~~^~~~~~~~~~
main.cpp:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf("%d", &a);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<immintrin.h>
#include<unordered_map>
using namespace std;
int c;
int n;
#define MAX 100002
vector<int> v;
unordered_map<int, vector<pair<int,int> > > dp;
int su[MAX];
int main(){
scanf("%d", &c);
scanf("%d", &n);
for (int i = 0; i < n; i++){
int a;
scanf("%d", &a);
v.push_back(a);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()),v.end());
dp[0].push_back(make_pair(0, 0));
for (int i = 0; i < v.size(); i++){
for (int j = 0; j <= c; j++){
int ind = j%v[i];
if (dp.count(ind) == 0){
su[j] = INT_MAX;
continue;
}
int ind2 = upper_bound(dp[ind].begin(), dp[ind].end(), make_pair(j, INT_MAX)) - dp[ind].begin();
ind2--;
if (ind2 < 0){
su[j] = INT_MAX;
continue;
}
int val = dp[ind][ind2].first;
int sa = abs(val - j);
sa /= v[i];
sa += dp[ind][ind2].second;
su[j] = sa;
}
dp.clear();
if (i + 1 == v.size()){
break;
}
for (int j = 0; j <= c; j++){
if (su[j] == INT_MAX){
continue;
}
dp[j%v[i + 1]].push_back(make_pair(j,su[j]));
}
for (int j = 0; j < v[i + 1]; j++){
if (dp.count(j)){
sort(dp[j].begin(), dp[j].end());
for (int k = 1; k < dp[j].size(); k++){
dp[j][k].second = min(dp[j][k].second, dp[j][k - 1].second + abs(dp[j][k - 1].first - dp[j][k].first) / v[i + 1]);
}
}
}
}
int ans = su[c];
if (ans == INT_MAX){
puts("-1");
return 0;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0