QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397447 | #3745. 排列 | SamponYW | WA | 638ms | 12128kb | C++14 | 1.7kb | 2024-04-24 09:09:47 | 2024-04-24 09:09:47 |
Judging History
answer
#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 20
#define P 1000000007
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
int s = 1;
while(n) {
if(n & 1) s = 1ll * s * p % P;
p = 1ll * p * p % P, n >>= 1;
}
return s;
}
il void chkmin(ll &x, ll y) {(x > y) && (x = y);}
int n, m, p[N + 5], tr[N]; ll dp[1 << N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
while(cin >> n >> m) {
FOR(i, 1, n) cin >> p[i];
sort(p + 1, p + 1 + n), mems(tr, 0);
while(m--) {
int u, v; cin >> u >> v, --u, --v;
tr[u] |= 1 << v, tr[v] |= 1 << u;
}
int A = (1 << n) - 1;
FOR(S, 0, A) dp[S] = 1e18; dp[0] = 0;
FOR(S, 0, A - 1) {
int s = 0, now = popc(S) + 1;
FOR(u, 0, n - 1) if(S >> u & 1)
s += popc(tr[u] & (S ^ A));
s = 1ll * s * (p[now] - p[now - 1]);
FOR(u, 0, n - 1) if(!(S >> u & 1))
chkmin(dp[S | (1 << u)], dp[S] + s);
}
cout << dp[A] << "\n";
}
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 638ms
memory: 12128kb
input:
10 2 840992398 69963455 393388491 672595500 780588893 558816806 9701416 311501224 368780848 930456829 1 6 1 4 10 0 411934118 140341026 198159044 539803943 494456917 558065612 943756089 206990595 183787315 315629195 10 16 162867395 704155151 462516209 378129375 222657670 984933865 265046889 623734262...
output:
81887267 0 2457714684 -3120818176 -902472537 3900698784 -1692227575 504197343 -1385586627 -608690103 -1724167949 2180299880 -2105160420 -1585522806 -838339082 -992734455 -4615390914 0 -1482984447 1547767459 11362940 3242222544 1439378250 -112716734 890795833 -281415710 952110870 365848095 1362692 40...
result:
wrong answer 4th numbers differ - expected: '6401740820', found: '-3120818176'