이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "holiday.h"
using namespace std;
int maxatr = 0, cnt[105];
long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
for(int i = 0; i < n; ++ i)
maxatr = max(maxatr, attraction[i]);
if(start == 0 && maxatr <= 100)
{
long long sum = 0;
for (int i = 0; i < n; ++ i)
{
cnt[attraction[i]] ++;
int freeto = d - i;
long long curr = 0;
for (int j = 100; j >= 0 && freeto; -- j)
{
curr += min(freeto, cnt[j]) * j;
long long taken = min(freeto, cnt[j]);
freeto -= taken;
}
sum = max(sum, curr);
}
return sum;
}
long long result = 0;
for (int i = 0; i <= start; ++ i)
{
priority_queue < long long > q;
long long sum = 0;
for (int ii = i; ii < start; ++ ii)
{
q.push(-attraction[ii]);
sum += attraction[ii];
}
int ext_left = start - i;
int ext_right = 0;
for (int j = start; j < n; ++ j)
{
q.push(-attraction[j]);
sum += attraction[j];
ext_right = j - start;
int left = d - ext_left - ext_right - min(ext_left, ext_right);
if(left < 0)continue;
while(q.size() > left)
{
sum += q.top();
q.pop();
}
/// cout << i << " " << j << " > " << sum << endl;
result = max(result, sum);
}
}
return result;
}
/*const int MAXN = 21, MAXMASK = (1 << 21) + 10;
int dp[MAXN][MAXMASK];
long long sum[MAXMASK];
long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
//cout << MAXN << " " << MAXMASK << endl;
int inf = 1e9;
for (int i = 0; i < n; ++ i)
{
for (int mask = 0; mask <= (1 << (n-1)); ++ mask)
{
dp[i][mask] = inf;
}
}
for (int mask = 0; mask <= (1 << (n-1)); ++ mask)
{
for (int v = 0; v < n; ++ v)
{
if(((1 << v) & mask))sum[mask] += 1LL * attraction[v];
}
}
dp[start][0] = 0;
long long ans = 0;
for (int mask = 0; mask <= (1 << (n-1)); ++ mask)
{
for (int v = 0; v < n; ++ v)
{
if(dp[v][mask] == inf)continue;
for (int add = 0; add < n; ++ add)
if(!(mask & (1 << add)))dp[add][(mask | (1 << add))] = min(dp[add][(mask | (1 << add))], dp[v][mask] + abs(v - add) + 1);
if(dp[v][mask] <= d)ans = max(ans, sum[mask]);
}
}
return ans;
}*/
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:50:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | while(q.size() > left)
| ~~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |