ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214179 | #2045. c | ThySecret | 10 | 0ms | 1172kb | C++11 | 1.8kb | 2024-11-15 22:09:01 | 2024-11-15 23:28:51 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);
typedef long long LL;
typedef pair<int, int> PII;
const int N = 200010;
const int INF = 0x3f3f3f3f;
template<typename Type>
inline void read(Type &res)
{
res = 0;
int ch = getchar(), flag = 0;
while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }
int n, ans = -1;
int a[N], w[N];
int per[N], vis[N], idx;
void dfs(int cur)
{
if (cur > n)
{
// for (int i = 2; i <= n; i ++)
// for (int j = 1; j < i; j ++) if (per[j] != a[per[i]]) return;
int res = 0;
for (int i = 1; i <= n; i ++) res += i * w[per[i]];
ans = max(ans, res);
// if (res == 32) for (int i = 1; i <= n; i ++) cout << per[i] << ' ';
// cout << "\n";
return;
}
for (int i = 1; i <= n; i ++)
{
if (vis[i]) continue;
if (cur == 1 || (!vis[i] && vis[a[i]]))
{
per[++ idx] = i, vis[i] = true;
dfs(cur + 1);
idx --, vis[i] = false;
}
}
}
signed main()
{
read(n);
for (int i = 1; i <= n; i ++) read(a[i]);
for (int i = 1; i <= n; i ++) read(w[i]);
dfs(1);
cout << ans << '\n';
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1172kb
input:
10 2 8 3 4 1 2 4 8 5 8 1 2 8 1 10 2 9 8 8 8
output:
-1
result:
ok "-1"
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1172kb
input:
10 0 9 5 5 0 0 0 0 0 0 576848570 9374579 447058478 375476508 17899037 890199416 691424702 96833317 4...
output:
-1
result:
wrong answer 1st words differ - expected: '27663373474', found: '-1'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1172kb
input:
15 0 0 0 12 6 0 0 14 8 0 0 7 6 15 0 1 4 7 1 5 1 1 6 8 6 1 1 2 6 2
output:
-1
result:
wrong answer 1st words differ - expected: '571', found: '-1'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1172kb
input:
15 10 0 13 14 0 0 4 9 0 2 0 0 0 0 10 699156165 159021634 857055962 44497989 345951671 893758337 8465...
output:
-1
result:
wrong answer 1st words differ - expected: '78062614530', found: '-1'
Test #5:
score: 0
Time Limit Exceeded
input:
1000 144 384 112 973 710 47 773 579 421 233 4 657 112 596 133 780 803 571 300 804 34 291 507 270 79 ...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
1000 349 415 281 956 749 201 628 217 723 900 513 106 618 978 176 448 834 704 763 266 466 533 192 379...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
100000 14420 84013 87193 82068 10374 79474 25939 9590 32198 3548 47938 85741 12568 14530 8858 60495 ...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
100000 26403 63914 61602 32321 29105 19251 73439 61190 72905 30337 25317 66634 83841 38470 96206 848...
output:
result:
Test #9:
score: 0
Runtime Error
input:
500000 331714 145478 6577 175958 171774 304559 166867 26414 92325 132061 8297 12915 470473 419957 48...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
500000 392409 161541 72825 120014 449034 320962 490925 62120 211235 236719 211792 410060 31166 20275...