이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Y8o "CollectingStamps3"
#define maxn (int) 205
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
#define f first
#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
}
void ctime() {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, L;
pii a[maxn];
namespace sub1 {
int dp[1 << 12][13][205];
int cost(int i, int j) {
pii x = a[i], y = a[j];
if(x.f > y.f) swap(x, y);
return min( y.f - x.f, L - y.f + x.f - 0 );
}
void solve() {
memset(dp, -0x3f, sizeof dp);
fi(i, 1, n) dp[(1 << (i - 1))][i][cost(0, i)] = cost(0, i) <= a[i].s;
fi(mask, 1, (1 << n) - 1) {
fi(i, 1, n) if(gb(mask, i - 1)) {
fi(j, 1, n) if(!gb(mask, j - 1)) {
int w = cost(i, j);
fi(t, 0, 200 - w) {
dp[mask ^ (1 << (j - 1))][j][t + w] =
max(dp[mask ^ (1 << (j - 1))][j][t + w], dp[mask][i][t] + (t + w <= a[j].s));
}
}
}
}
int ans = 0;
fi(i, 1, n) {
fi(t, 0, 200) {
ans = max(ans, dp[(1 << n) - 1][i][t]);
}
}
cout << ans;
}
}
void solve() {
cin >> n >> L ;
fi(i, 1, n) cin >> a[i].f;
fi(i, 1, n) cin >> a[i].s;
if(n <= 12 && L <= 200) return sub1 :: solve(), void();
}
int main() {
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
ctime();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t3.cpp: In function 'void sub1::solve()':
ho_t3.cpp:53:39: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
53 | fi(i, 1, n) if(gb(mask, i - 1)) {
| ~~^~~
ho_t3.cpp:6:25: note: in definition of macro 'gb'
6 | #define gb(i, j) ((i >> j) & 1)
| ^
ho_t3.cpp:54:44: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
54 | fi(j, 1, n) if(!gb(mask, j - 1)) {
| ~~^~~
ho_t3.cpp:6:25: note: in definition of macro 'gb'
6 | #define gb(i, j) ((i >> j) & 1)
| ^
ho_t3.cpp: In function 'void iof()':
ho_t3.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |