QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393882 | #8228. 排序 | zhjxaoini | 100 ✓ | 1373ms | 60060kb | C++14 | 4.5kb | 2024-04-19 16:05:46 | 2024-04-19 16:05:47 |
Judging History
answer
#ifndef LOCAL_RUN
#define NDEBUG
#endif
#ifdef GNU_DEBUG
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#define _GLIBCXX_SANITIZE_VECTOR 1
#endif
#include <bits/stdc++.h>
namespace {
#define mset(a, b) memset(&a, b, sizeof(a))
#define ALL(v) std::begin(v), std::end(v)
#define RANGE(a, l, r) (std::begin(a) + (l)), (std::begin(a) + ((r) + 1))
#define fir(i, a, b, ...) for (int i = (a), ##__VA_ARGS__; i <= (b); ++i)
#define firr(i, a, b, ...) for (int i = (a), ##__VA_ARGS__; i >= (b); --i)
#ifdef LOCAL_RUN
template<class T> void dbgpr(const T& x) {std::cerr << x << std::endl;}
template<class T, class... Args> void dbgpr(const T& x, const Args&... args) {std::cerr << x << ", ", dbgpr(args...);}
template<class... Args> void dbgprint(const char* s, const Args&... args) {std::cerr << s << " = ", dbgpr(args...);}
#define debug(...) dbgprint(#__VA_ARGS__, __VA_ARGS__)
#define DEBUG if (true)
#else
#define debug(...) void()
#define DEBUG if (false)
#endif
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
template<class T> void rei(T& x) {
bool f = false; int ch; x = 0;
while (!isdigit(ch = getchar())) f = ch == '-';
do x = x * 10 + (ch & 15); while (isdigit(ch = getchar()));
if (f) x = -x;
}
template<class T1, class T2> bool cmax(T1& a, const T2& b) {return a < b ? a = b, true : false;}
template<class T1, class T2> bool cmin(T1& a, const T2& b) {return b < a ? a = b, true : false;}
using namespace std;
const int MOD = 1e9 + 7;
inline int llmod(LL x) {assert(x >= 0); return int(x % MOD);}
inline int mod1(int x) {assert(0 <= x && x < 2 * MOD); return x < MOD ? x : x - MOD;}
inline int mod2(int x) {assert(-MOD <= x && x < MOD); return x >= 0 ? x : x + MOD;}
inline void madd(int& x, int y) {x = mod1(x + y);}
inline void msub(int& x, int y) {x = mod2(x - y);}
inline void mtim(int& x, int y) {x = llmod((LL)x * y);}
inline void maddtim(int& x, int y, int z) {x = llmod(x + (LL)y * z);}
inline int qpow(int a, int b = MOD - 2) {
int ans = 1;
for (; b; b >>= 1) {
if (b & 1) mtim(ans, a);
mtim(a, a);
}
return ans;
}
const int MAXN = 35;
const int MAXS = 1.5e6 + 5;
int n, m, full;
array<int, MAXN> d;
vector<int> state;
unordered_map<int, int> id;
void dfs_enum(int idx, int msk) {
if (idx == n) {
state.push_back(msk);
return;
}
dfs_enum(idx + 1, msk);
if (idx >= d[1] && !(msk >> (idx - d[1]) & 1)) return;
dfs_enum(idx + 1, msk | 1 << idx);
}
array<unsigned, 5> multi;
void solve(int msk) {
static array<unsigned, MAXN> arr;
fir (i, 0, n - 1) {
if (msk >> i & 1) {
arr[i] = 1U << 31 | 1U << i;
} else {
arr[i] = 0;
}
}
ULL sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
fir (idx, 1, m) {
int len = d[idx];
fir (i, len, n - 1) {
if (arr[i]) {
for (int j = i; j >= len && arr[j - len]; j -= len) {
arr[j - len] |= arr[j];
arr[j] = 1U << 31;
}
} else {
for (int j = i; j >= len && arr[j - len]; j -= len) {
sum0 += arr[j - len] & 0b00000010000100001000010000100001U;
sum1 += arr[j - len] & 0b00000100001000010000100001000010U;
sum2 += arr[j - len] & 0b00001000010000100001000010000100U;
sum3 += arr[j - len] & 0b00010000100001000010000100001000U;
sum4 += arr[j - len] & 0b00100001000010000100001000010000U;
arr[j] = arr[j - len];
arr[j - len] = 0;
}
}
}
}
multi = {unsigned(sum0), unsigned(sum1 >> 1), unsigned(sum2 >> 2), unsigned(sum3 >> 3), unsigned(sum4 >> 4)};
}
int calc(int key) {
return multi[key % 5] >> (key - key % 5) & 31;
}
array<int, MAXS> mx, cnt;
void realmain() {
// freopen("data.in", "r", stdin);
rei(n), rei(m), full = (1 << n) - 1;
fir (i, 1, m) rei(d[i]);
dfs_enum(0, 0);
id.reserve(state.size());
fir (i, 0, (int)state.size() - 1) id[state[i]] = i;
debug(state.size());
assert(!state[0]), assert(state.back() == full);
cnt[0] = 1;
fir (cur, 1, (int)state.size() - 1) {
int S = state[cur];
solve(S);
fir (i, 0, n - 1) if (S >> i & 1) if ((LL)~S >> (i + d[1]) & 1) {
assert(id.count(S ^ 1 << i));
int t = id[S ^ 1 << i];
int r1 = calc(i);
int r2 = mx[t];
int r3 = cnt[t];
if (cmax(mx[cur], r1 + r2)) cnt[cur] = r3;
else if (mx[cur] == r1 + r2) madd(cnt[cur], r3);
}
}
assert(id.size() == state.size());
printf("%d %d\n", mx[(int)state.size() - 1], cnt[(int)state.size() - 1]);
}}
signed main(){return realmain(),0;}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 18
Accepted
Test #1:
score: 18
Accepted
time: 0ms
memory: 3828kb
input:
2 2 2 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
5 4 5 4 2 1
output:
6 4
result:
ok 2 number(s): "6 4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
8 4 6 3 2 1
output:
15 4
result:
ok 2 number(s): "15 4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
8 6 8 7 5 4 2 1
output:
14 2
result:
ok 2 number(s): "14 2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
8 3 8 7 1
output:
22 7
result:
ok 2 number(s): "22 7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
8 1 1
output:
28 1
result:
ok 2 number(s): "28 1"
Subtask #2:
score: 27
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 27
Accepted
time: 1ms
memory: 3928kb
input:
16 2 6 1
output:
77 15
result:
ok 2 number(s): "77 15"
Test #8:
score: 0
Accepted
time: 7ms
memory: 4368kb
input:
16 8 10 9 8 7 6 5 4 1
output:
57 5
result:
ok 2 number(s): "57 5"
Test #9:
score: 0
Accepted
time: 2ms
memory: 4488kb
input:
16 10 10 9 8 7 6 5 4 3 2 1
output:
57 3
result:
ok 2 number(s): "57 3"
Test #10:
score: 0
Accepted
time: 7ms
memory: 4376kb
input:
16 7 10 9 8 6 5 4 1
output:
49 1
result:
ok 2 number(s): "49 1"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3992kb
input:
16 4 7 6 2 1
output:
52 9
result:
ok 2 number(s): "52 9"
Subtask #3:
score: 21
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 21
Accepted
time: 3ms
memory: 4088kb
input:
22 3 5 3 1
output:
100 1
result:
ok 2 number(s): "100 1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
22 1 1
output:
231 1
result:
ok 2 number(s): "231 1"
Test #14:
score: 0
Accepted
time: 66ms
memory: 8468kb
input:
22 4 10 8 3 1
output:
97 4
result:
ok 2 number(s): "97 4"
Test #15:
score: 0
Accepted
time: 71ms
memory: 8388kb
input:
22 5 10 7 6 3 1
output:
92 70
result:
ok 2 number(s): "92 70"
Test #16:
score: 0
Accepted
time: 74ms
memory: 8276kb
input:
22 6 10 9 8 7 3 1
output:
97 1
result:
ok 2 number(s): "97 1"
Test #17:
score: 0
Accepted
time: 93ms
memory: 8392kb
input:
22 10 10 9 8 7 6 5 4 3 2 1
output:
109 1
result:
ok 2 number(s): "109 1"
Subtask #4:
score: 10
Accepted
Test #18:
score: 10
Accepted
time: 2ms
memory: 3980kb
input:
14 2 10 1
output:
61 210
result:
ok 2 number(s): "61 210"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
18 2 2 1
output:
117 1
result:
ok 2 number(s): "117 1"
Test #20:
score: 0
Accepted
time: 340ms
memory: 30984kb
input:
30 2 9 1
output:
264 84
result:
ok 2 number(s): "264 84"
Test #21:
score: 0
Accepted
time: 251ms
memory: 25892kb
input:
29 2 9 1
output:
253 36
result:
ok 2 number(s): "253 36"
Test #22:
score: 0
Accepted
time: 43ms
memory: 7288kb
input:
25 2 8 1
output:
195 8
result:
ok 2 number(s): "195 8"
Subtask #5:
score: 24
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #23:
score: 24
Accepted
time: 974ms
memory: 56612kb
input:
30 4 10 9 5 1
output:
188 40
result:
ok 2 number(s): "188 40"
Test #24:
score: 0
Accepted
time: 1296ms
memory: 56788kb
input:
30 9 10 9 8 7 6 5 4 3 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #25:
score: 0
Accepted
time: 1306ms
memory: 56796kb
input:
30 8 10 9 8 7 4 3 2 1
output:
154 1
result:
ok 2 number(s): "154 1"
Test #26:
score: 0
Accepted
time: 1276ms
memory: 56924kb
input:
30 8 10 8 7 6 5 4 3 1
output:
155 1
result:
ok 2 number(s): "155 1"
Test #27:
score: 0
Accepted
time: 1163ms
memory: 60060kb
input:
30 6 10 8 6 4 3 1
output:
150 4
result:
ok 2 number(s): "150 4"
Test #28:
score: 0
Accepted
time: 1373ms
memory: 57616kb
input:
30 10 10 9 8 7 6 5 4 3 2 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #29:
score: 0
Accepted
time: 808ms
memory: 44996kb
input:
29 6 10 9 7 5 3 1
output:
129 200
result:
ok 2 number(s): "129 200"
Extra Test:
score: 0
Extra Test Passed