結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-02-10 16:34:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,573 bytes |
| 記録 | |
| コンパイル時間 | 1,453 ms |
| コンパイル使用メモリ | 105,036 KB |
| 実行使用メモリ | 814,796 KB |
| 最終ジャッジ日時 | 2024-06-23 18:17:30 |
| 合計ジャッジ時間 | 6,246 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 MLE * 1 -- * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
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",&N,&S);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:26:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | for( int i = 0 ; i <N; i++) scanf("%d", &P[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
int main(){
int N,S;
scanf("%d%d",&N,&S);
int P[N];
for( int i = 0 ; i <N; i++) scanf("%d", &P[i]);
int sum=0;
for( int i = 0 ; i <N; i++ ) sum+=P[i];
int rest[N+1];
int minVal[N+1];
rest[N]=0;
minVal[N]= INT_MAX;
for( int i = N-1; i>=0 ;i--){
rest[i] = rest[i+1]+P[i];
minVal[i] = min(minVal[i+1],P[i]);
}
queue< pair<int,vector<int> > > q;
vector< vector<int> > ans;
q.push( make_pair( 0,vector<int>() ) );
for( int i = 0 ; i <N; i++ ){
int size = q.size();
for( int j = 0 ; j < size; j++){
pair<int,vector<int> > p = q.front();
vector<int> seq = p.second;
int cost = p.first;
q.pop();
if( cost+minVal[i+1] <= S && cost + rest[i+1] >= S ){
q.push( make_pair( cost, seq ) );
}
cost += P[i];
seq.push_back(i);
if( cost == S ){
ans.push_back(seq);
}
if( cost+minVal[i+1] <= S && cost + rest[i+1] >= S ){
q.push( make_pair( cost, seq ) );
}
}
}
sort(ans.begin(),ans.end());
for( int i = 0 ; i < (int)ans.size(); i++){
for( int j = 0 ; j < (int)ans[i].size(); j++ ){
cout << 1+ans[i][j]<<" ";
}
cout << endl;
}
return 0;
}
yaoshimax