Submission #16845


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<stdio.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<map>
int dp[10002];
int memo[10002];
void f(){
int n,y,top=-1;
std::vector<int> ms,ms2;
std::map<int,int> maps;
scanf("%d",&n);
memset(dp,0,sizeof(dp));
memset(memo,0,sizeof(dp));
int all=0;
for(int i=0;i<n;i++){
int l;
scanf("%d",&l);
dp[l]++;
if(top<l){
top=l;
}
all+=l;
}
scanf("%d",&y);
for(int i=0;i<y;i++){
int m;
scanf("%d",&m);
ms.push_back(m);
ms2.push_back(m);
}
std::sort(ms.begin(),ms.end());
int sum=0;
for(int i=top;i>0;i--){
sum+=dp[i];
dp[i]=sum;
}
for(int i=top;i>0;i--){
int sum=0;
for(int j=1;j*i<=top;j++){
int p=j*i;
sum+=dp[p];
}
memo[i]=sum;
}
int p2=top;
int ans=-1;
for(int i=0;i<ms.size();i++){
int m=ms[i];
while(p2>=0){
if(memo[p2]>=m){
maps[m]=p2;
int l1=all-m*p2;
if((ans==-1)||(ans>l1)){
ans=l1;
}
break;
}
p2--;
}
}
bool ok=true;
for(int i=0;i<ms2.size();i++){
int m=ms2[i];
if(maps.find(m)==maps.end()){
printf("NA\n");
ok=false;
}else{
printf("%d\n",maps[m]);
}
}
if((ok==true)&&(ans!=-1)){
printf("%d\n",ans);
}else{
printf("0\n");
}
}
int main(){
f();
}

ステータス

項目 データ
問題 0045 - 浜名湖鰻と見習い料理人
ユーザー名 sinapusu2002
投稿日時 2017-05-08 12:08:32
言語 C++11
状態 Accepted
得点 20
ソースコード長 1292 Byte
最大実行時間 39 ms
最大メモリ使用量 716 KB

セット

セット 得点 Cases
1 ALL 20 / 20 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
HamanakoInput1.txt AC 20 ms 480 KB
1
HamanakoInput2.txt AC 13 ms 652 KB
1
HamanakoInput3.txt AC 21 ms 564 KB
1
HamanakoInput4.txt AC 39 ms 604 KB
1
HamanakoInput5.txt AC 14 ms 644 KB
1
HamanakoInput6.txt AC 15 ms 660 KB
1
HamanakoInput7.txt AC 13 ms 704 KB
1
HamanakoInput8.txt AC 36 ms 704 KB
1
HamanakoInput9.txt AC 16 ms 716 KB
1
HamanakoInputA.txt AC 22 ms 584 KB
1