이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 100010
#define N 5010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
x += k;
x %= mod;
if(x < 0) x += mod;
}
void del(int &x, int k)
{
x -= k;
x %= mod;
if(x < 0) x += mod;
}
int n,m;
array<int,3> a[N];
array<int,3> b[N];
int f[2][maxn];
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
fo(i,1,n) cin >> a[i][0] >> a[i][1] >> a[i][2];
cin >> m;
fo(i,1,n) cin >> b[i][0] >> b[i][1] >> b[i][2];
sort(a + 1,a + n + 1,[](array<int,3> u,array<int,3> v)
{
return u[1] > v[1];
});
sort(b + 1,b + m + 1,[](array<int,3> u,array<int,3> v)
{
return u[1] > v[1];
});
// fo(i,1,n) cout << a[i][0] << ' ' << a[i][1] << ' ' << a[i][2] << "\n";
// en;
// fo(i,1,m) cout << b[i][0] << ' ' << b[i][1] << ' ' << b[i][2] << "\n";
int pos = 1;
memset(f,-0x3f,sizeof f);
f[0][0] = 0;
fo(i,1,n)
{
fo(j,0,n * 50) maximize(f[i & 1][j],f[i & 1 ^ 1][j]);
fo(j,a[i][0],n * 50) maximize(f[i & 1][j],f[i & 1 ^ 1][j - a[i][0]] - a[i][2]);
// cout << a[i][0] << ' ' << f[i & 1][8] << ' ' << f[i & 1 ^ 1][0];en;
while(pos <= m and b[pos][1] <= a[i][1] and b[pos][1] > a[i + 1][1])
{
fo(j,0,n * 50 - b[pos][0]) maximize(f[i & 1][j],f[i & 1][j + b[pos][0]] + b[pos][2]);
pos++;
}
}
cout << *max_element(f[n & 1],f[n & 1] + n * 50 + 1);
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main()
| ^~~~
clo.cpp: In function 'int main()':
clo.cpp:92:49: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
92 | fo(j,0,n * 50) maximize(f[i & 1][j],f[i & 1 ^ 1][j]);
| ~~^~~
clo.cpp:93:55: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
93 | fo(j,a[i][0],n * 50) maximize(f[i & 1][j],f[i & 1 ^ 1][j - a[i][0]] - a[i][2]);
| ~~^~~
clo.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |