# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
758006 |
2023-06-14T04:38:49 Z |
jer033 |
Fruits (NOI22_fruits) |
C++17 |
|
219 ms |
16728 KB |
#include <algorithm>
#include <iostream>
int assigned[400005];
long long costs[400005];
long long answer[400005];
int available[400005];//boolean
int toassign[400005];//list
int avail[400005];//list
using namespace std;
int factorial(int n)
{
if (n<=1)
return 1;
return n*factorial(n-1);
}
int main()
{
int n;
cin >> n;
int subtwo=1;
for (int i=1; i<=n; i++)
{
available[i]=1;
}
int mychoice=0;
for (int i=1; i<=n; i++)
{
cin >> assigned[i];
if (assigned[i]>0)
{
subtwo=0;
available[assigned[i]]=0;
}
else
{
mychoice++;
toassign[mychoice]=i;
}
}
if (subtwo)
{
answer[0]=0;
for (int i=1; i<=n; i++)
{
cin >> costs[i];
answer[i]=answer[i-1]+costs[i];
}
for (int i=0; i<n; i++)
{
cout << answer[n]-answer[n-1-i];
if (i!=(n-1))
cout << ' ';
else
cout << '\n';
}
}
else if (n<=8)
{
for (int i=1; i<=n; i++)
cin >> costs[i];
//let's assume subtask 1 holds
int count = 0;
for (int i=1; i<=n; i++)
{
if (available[i])
{
count++;
avail[count]=i;
}
}
int ways=factorial(count);
//copy pasted code from gym badges, edited
for (int i=1; i<=ways; i++)
{
//put the tuple "avail" into the "assigned" array using "toassign" and solve for each k, store answer in max
for (int j=1; j<=count; j++)
{
assigned[toassign[j]]=avail[j];
}
int currbest=0;
long long money=0;
for (int j=1; j<=n; j++)
{
//cout << assigned[j];
if (assigned[j]>currbest)
{
currbest=assigned[j];
money+=costs[assigned[j]];
}
answer[j]=max(answer[j], money);
}
//cout << '\n';
//code the next permutation
int swapa=count-1;
while (avail[swapa]>avail[swapa+1])
swapa--;
int swapb=swapa+1;
for (int j=swapa+2; j<=count; j++)
{
if (avail[j]>avail[swapa])
swapb=j;
}
int x=avail[swapa];
avail[swapa]=avail[swapb];
avail[swapb]=x;
sort(avail+swapa+1, avail+count+1);
}
for (int i=1; i<=n; i++)
{
cout << answer[i];
if (i!=n)
cout << ' ';
else
cout << '\n';
}
}
else
{
cout << "I was not made to do this.\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
1108 KB |
Output is correct |
4 |
Correct |
120 ms |
8504 KB |
Output is correct |
5 |
Correct |
219 ms |
16728 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
4696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
1108 KB |
Output is correct |
14 |
Correct |
120 ms |
8504 KB |
Output is correct |
15 |
Correct |
219 ms |
16728 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |